0
我試圖將用戶輸入作爲參數傳遞給構造函數,而不是將它傳遞給一個方法。當我這樣做時,我在第20行(或創建構造函數的地方)出現錯誤消息「in initialize:錯誤的參數數量爲< 1 for 0>」。爲什麼構造函數不會參數?將用戶輸入傳遞給構造函數Ruby
class Beginnerbudget
def rate_savings(amount)
@amount = amount
if amount >= 501
puts "You have $#{amount} in your account. Keep up the good
work!"
elsif amount <= 500 && amount >= 101
puts "You only have $#{amount} in your account. Try and save
a little more this month."
else amount < 100
puts "Yikes, you only have $#{amount} in your account! Sell
a kidney quick!"
end
end
end
puts "How much money do you have in your checking account?"
amount = gets.chomp.to_i
beginner_budget = Beginnerbudget.new(amount)
beginner_budget.rate_savings`