M
M
Max2015-05-09 14:33:53
ruby
Max, 2015-05-09 14:33:53

Why doesn't the .empty method work in Ruby?

Hello, I tried to write a simple ruby ​​program. But for some reason the empty method doesn't want to work. Here is the code:

class HaveMoney
  attr_accessor :haveMoney

  def initialize
    @haveMoney = haveMoney
  end

  def checkMoney
    if @haveMoney.empty?
      puts "Вы ничего не ввели"
    elsif @haveMoney <= 99
      puts "Плохо"
    elsif @haveMoney >= 100
      puts "Круто"				
    end
  end
end
 mg = HaveMoney.new
 puts "Введите сумму: "
 mg.haveMoney = gets.chomp.to_i
 mg.checkMoney

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Y
Yuri, 2015-05-09
@maxprof

An empty string equals 0 when translated.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question