Ruby/Number/nonzero

Материал из Wiki.crossplatform.ru

Перейти к: навигация, поиск

Содержание

If it is a nonzero

op = 2
if op.nonzero? # is it nonzero?
  puts 12 / op
else
  puts "Can"t divide by zero."
end



If it is not a zero, then

op = 0
if !op.zero? # not a zero?
  puts 12 / op
else
  puts "Can"t divide by zero."
end



Is it a nonzero

op = 0
op.nonzero? # => false



Is it a zero

op = 0
op.zero? # => true