I’ve been trying to test out some stuff in irb and it doesn’t recognize commands like
2.weeks.ago
and
10.hours.ago
The error I get is the following:
1.9.3p258 :002 > 2.weeks.ago
NoMethodError: undefined method `weeks' for 2:Fixnum
from (irb):2
from /Users/Avneesh/.rvm/rubies/ruby-1.9.3-head/bin/irb:16:in `<main>'
For reference…
Ruby version: 1.9.3p258
OS: Mac OS X 10.8
Any ideas on why this is happening? I’m pretty sure I don’t need to require/include any modules/libraries. Any help would be appreciated.
Thanks.
These methods are defined in activesupport gem. You need to include active_support/all
There are two ways:
Edit: As pointed out by Jörg in the comments, you can just require
active_support/core_ext/integer/timeto include Time specific functions, including this one.