ruby – 未定义的方法`zone` for Time:Class,需要active_support / time_with_zone

我在 Ruby 2.2.1上安装了active_support 4.2,所以我想使用它
Time.zone.parse('2007-02-10 15:30:45')

如下所述:http://api.rubyonrails.org/classes/ActiveSupport/TimeWithZone.html

但即使在需要active_support和active_support / time_with_zone之后,我似乎仍然无法使用Time.zone.注意:

2.2.1 :002 >   require "active_support"
 => true
2.2.1 :003 > Time.zone
NoMethodError: undefined method `zone' for Time:Class
2.2.1 :004 > require "active_support/time_with_zone"
 => true
2.2.1 :005 > Time.zone
NoMethodError: undefined method `zone' for Time:Class

这是怎么回事?

解决方法

Time类的zone类方法实际上位于active_support / core_ext / time / zones中.如果您真的想使用Time.zone,则可以要求该类,但更好的方法可能需要active_support / all

建议的解决方

require "active_support/all"

如果你想查看active_support的源代码堡,请查看github repo

相关文章

validates:conclusion,:presence=>true,:inclusion=>{...
一、redis集群搭建redis3.0以前,提供了Sentinel工具来监控各...
分享一下我老师大神的人工智能教程。零基础!通俗易懂!风趣...
上一篇博文 ruby传参之引用类型 里边定义了一个方法名 mo...
一编程与编程语言 什么是编程语言? 能够被计算机所识别的表...
Ruby类和对象Ruby是一种完美的面向对象编程语言。面向对象编...