这是我的代码:
item = []
today = Date.today
dates = {"3 years" => today << 12*3, "2 years" => today << 12*2,
"1.5 years" => today << 12*1.5,"1 year" => today << 12, "6 months" => today << 6,
"3 months" => today << 3, "today" => today}
每次运行它时,我都会`<<': invalid date (ArgumentError)
在开始的行上收到此错误。dates...
怎么了?today
应该是一个有效的日期,我尝试在乘法和值字段周围加上括号,但仍然是那个错误。当我在 irb 中尝试时,效果很好。文件顶部需要日期。