require 'date'
now = DateTime.now
sunday = now - now.wday
>> sunday = now - now.wday
=> #<DateTime: 53058180361250947/21600000000,-5/24,2299161>
由于sunday
是DateTime
对象,我应该能够调用其实例方法如to_date
或midnight
,这两者的Rails文档中列出。为什么没有任何实例方法在DateTime对象上工作?
然而,这是我所得到的
>> sunday.to_time
NoMethodError: undefined method `to_time' for #<DateTime: 53058180361250947/21600000000,-5/24,2299161>
from (irb):17
其实没有这些实例的方法进行这项工作。我使用的是irb模式,我不知道发生了什么。任何人都可以告诉我如何解决这个问题?
如何加载的ActiveSupport? – ZeroNegOne
'require'activesupport/all''加载所有内容 – Ven