Tag: chomp

Sublime文本无法理解gets.chomp

我使用Sublime Text在ruby中编写了这个简单的程序,出于某种原因,如果我使用Sublime文本内置系统构建它,那么我得到以下错误 `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”) […]