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`