1
我用崇高的文本和寫在紅寶石這個簡單的程序由於某種原因,如果我建立它用崇高文本內置系統,然後我得到以下錯誤崇高文字無法理解gets.chomp
`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