开发者

What module(s) do I need to include to get 5.seconds to work in Ruby?

Because apparently require 'date' doesn't include the method hours or seconds etc:

undefined method `hours' for 5:Fixnum (NoMethodError)

Am I missing something? Is 5.seconds only so开发者_高级运维mething you can do in Rails? If so, what is the require statement I need to get this to work in a ruby script?


Old question, but for the googlers like me:

require 'active_support/time'

For gem version 3.2.11, anyway.


The following works for me

irb
>> require 'active_support'
=> true
>> 5.hours
=> 18000 seconds

Depending on your environment and rails version you may need to require 'rubygems' this should be done before the require 'active_support' line.

You may also have to require 'activesupport' instead of active_support if you have an older version of rails.


ActiveSupport::CoreExtensions::Numeric::Time maybe

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜