views:

55

answers:

2

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?

+2  A: 

ActiveSupport::CoreExtensions::Numeric::Time maybe

Tom Womack
Link: http://api.rubyonrails.org/classes/ActiveSupport/CoreExtensions/Numeric/Time.html
Zachary
+4  A: 

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.

Steve Weet
I'll accept this answer if you edit your post (I will downvote if you dont edit it.) You need to require 'rubygems' first before active_support.
DJTripleThreat
The original script works for me as is but edited anyway. Please note that for library code requiring rubygems is generally considered bad practice see http://www.rubyinside.com/why-using-require-rubygems-is-wrong-1478.html
Steve Weet
well its not bad practice when its THE THING you need for it to actually work.
DJTripleThreat
+1 for staring your benefactor down
nasmorn