Rails 好奇怪的问题 大家帮忙看看

ibachue · March 22, 2013 · Last by iBachue replied at March 22, 2013 · 1587 hits

Hi all,

大家帮忙看看,为什么

>> 1.5.months.to_i
=> 3888000
>> 45.days.to_i
=> 3888000

但是

>> 1.5.months.ago
=> Tue Jan 22 07:12:39 -0700 2013
>> 45.days.ago
=> Tue Feb 05 07:12:45 -0700 2013

好奇怪的问题啊 1.5.months.ago相当于2.months.ago了 但是1.5.months.to_i却和45.days.to_i是一样的 这是为什么呀 Ruby 或是 Rails 的 bug 嘛?

好奇怪,为什么我

NoMethodError: undefined method `months' for 1.5:Float

#1 楼 @zgm Ruby 1.8.7 Rails 2.3

You need to Sign in before reply, if you don't have an account, please Sign up first.