我使用 Sublime Text 在 ruby 中编写了这个简单的程序,出于某种原因,如果我使用 Sublime text 内置系统构建它,那么我会收到以下错误
`deposit': undefined method `chomp' for nil:NilClass (NoMethodError)
如果我使用 cmd 运行它,它会完美运行。
class BankAccount
def initialize(name)
@transactions = []
@balance = 0
end
def deposit
print "How much do you want to deposit?"
amount = gets.chomp
@balance += amount.to_f
puts "$#{amount} is deposited"
end
def show_balance
puts "Your balance is #{@balance}"
end
end
bank_account = BankAccount.new("Rohit Begani")
bank_account.class # => BankAccount
bank_account.deposit
bank_account.show_balance