-5

每次我在 Ruby 上打开它时,Ruby 几乎都会立即关闭,因为它无法读取代码中的某些内容。所以代码中有一个错误,但我查看了所有内容,但似乎找不到它。我需要一些帮助才能使此代码正常工作。非常感谢您!

Time.now=apply_time
if apply_time.month <=3
price=45 
elsif apply_time.month <=5
price=55 
elsif apply_time.month <=7
price=65 
else 
price=0 
end
puts 'The fee to apply for the competition is $ ' + price.to_s + '.00 when you apply on the date of today, ' + Time.now.to_s +'.'
puts 'If your fee came up as $0.00, then that is because the competition has ended. But do not worry, there is always next year!'
Sleep 20
4

1 回答 1

3

您的第一行正在尝试分配apply_timeTime.now

反过来试试:

apply_time = Time.now

顺便说一句,如果你从 irb 运行它,你会看到错误:

NameError: undefined local variable or method `apply_time' for main:Object

但即使你提前定义了 apply_time,你也会得到:

NoMethodError: undefined method `now=' for Time:Class

因为你不能在不破坏 Time 类的情况下为当前时间赋值。

于 2012-12-31T02:56:27.403 回答