Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 something you can do in Rails? If so, what is the require statement I need to get this to work in a ruby script?

like image 365
aarona Avatar asked May 21 '10 18:05

aarona


People also ask

What does Included do in Ruby?

The include method has a callback which is invoked whenever a module is included into another module/class - the included method. It is executed in the context of the mixin module and should be defined there. Its signature is self. included(base) where base is the target class.


2 Answers

Old question, but for the googlers like me:

require 'active_support/time' 

For gem version 3.2.11, anyway.

like image 162
Lou Zell Avatar answered Sep 19 '22 14:09

Lou Zell


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.

like image 27
Steve Weet Avatar answered Sep 20 '22 14:09

Steve Weet