# Why 1.hour doesn't work?

**URL:** <https://www.ruby-forum.com/t/why-1-hour-doesnt-work/108337>\
**Category:** Ruby\
**Created:** [July 2, 2007, 1:29pm UTC](https://www.ruby-forum.com/t/why-1-hour-doesnt-work/108337 "2007-07-02T13:29:00Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kenneth](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/94ad74/32.png) [@Kenneth](https://www.ruby-forum.com/u/Kenneth)\
**Post date:** [July 2, 2007, 1:29pm UTC](https://www.ruby-forum.com/t/why-1-hour-doesnt-work/108337/1 "2007-07-02T13:29:00Z")

</div>

this is a newbie question:

so if it is in Ruby on Rails, then 1.hour and 1.hour.from\_now both  
work…  
now then, how come in irb, they both don’t work?

---

<div class="post-metadata">

**Author:** ![Kenneth](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/94ad74/32.png) [@Kenneth](https://www.ruby-forum.com/u/Kenneth)\
**Post date:** [July 2, 2007, 1:38pm UTC](https://www.ruby-forum.com/t/why-1-hour-doesnt-work/108337/2 "2007-07-02T13:38:34Z")

</div>

Hi –

On Mon, 2 Jul 2007, Kenneth wrote:

> this is a newbie question:
> 
> so if it is in Ruby on Rails, then 1.hour and 1.hour.from\_now both  
> work…  
> now then, how come in irb, they both don’t work?

Because they’re defined in a Rails library, not in the Ruby language.

David

---

<div class="post-metadata">

**Author:** ![Kenneth](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/94ad74/32.png) [@Kenneth](https://www.ruby-forum.com/u/Kenneth)\
**Post date:** [July 2, 2007, 1:44pm UTC](https://www.ruby-forum.com/t/why-1-hour-doesnt-work/108337/3 "2007-07-02T13:44:35Z")

</div>

2007/7/2, Kenneth [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> this is a newbie question:
> 
> so if it is in Ruby on Rails, then 1.hour and 1.hour.from\_now both  
> work…  
> now then, how come in irb, they both don’t work?

They’re not part of the core language or even the standard library,  
but added by Rails. Ruby’s classes are open, so libraries can add new  
methods even to core classes (in this cas Numeric).

If you want to uses these methods outside of Rails, you need to load  
the part of Rails which contributes them (in this case ActiveSupport):

% irb  
irb(main):001:0\> require ‘rubygems’  
=\> false  
irb(main):002:0\> require ‘active\_support’  
=\> true  
irb(main):003:0\> 1.hour  
=\> 3600

---

<div class="post-metadata">

**Author:** ![Kenneth](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/94ad74/32.png) [@Kenneth](https://www.ruby-forum.com/u/Kenneth)\
**Post date:** [July 3, 2007, 12:06am UTC](https://www.ruby-forum.com/t/why-1-hour-doesnt-work/108337/4 "2007-07-03T00:06:26Z")

</div>

Kenneth Ll wrote:

> as when including 1 and it detects it lacks the other one, then it will  
> include the other one too).
> 
> so i think the other way
> 
> ruby script/console
> 
> will work too huh? (my ruby was set up with rails last time but right  
> now it doesn’t have the PATH to do things any more…)

Typically you do something external to Ruby to ensure that rubygems is  
always loaded. Then you can stop worrying about it. The easiest thing to  
do is set the RUBYOPTS environment variable to the value “rubygems”. How  
you set the variable depends on the shell you’re using. If you’re using  
bash, for example, do this:

export RUBYOPTS=rubygems

If you’re using another shell there will be a slightly different  
command.

---

<div class="post-metadata">

**Author:** ![Kenneth](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/94ad74/32.png) [@Kenneth](https://www.ruby-forum.com/u/Kenneth)\
**Post date:** [July 2, 2007, 11:55pm UTC](https://www.ruby-forum.com/t/why-1-hour-doesnt-work/108337/5 "2007-07-02T23:55:47Z")

</div>

> % irb  
> irb(main):001:0\> require ‘rubygems’  
> =\> false  
> irb(main):002:0\> require ‘active\_support’  
> =\> true  
> irb(main):003:0\> 1.hour  
> =\> 3600

both are needed huh? is there a way just to include one module? (such  
as when including 1 and it detects it lacks the other one, then it will  
include the other one too).

so i think the other way

ruby script/console

will work too huh? (my ruby was set up with rails last time but right  
now it doesn’t have the PATH to do things any more…)

---

<div class="post-metadata">

**Author:** ![Kenneth](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/94ad74/32.png) [@Kenneth](https://www.ruby-forum.com/u/Kenneth)\
**Post date:** [July 3, 2007, 2:59pm UTC](https://www.ruby-forum.com/t/why-1-hour-doesnt-work/108337/6 "2007-07-03T14:59:17Z")

</div>

This is why I always stress that people should learn Ruby first before  
moving on to Rails. Rails does so much to the Ruby stdlib that it’s very  
difficult to get a grasp on things if you’re new to both.

Please read through this book to get you started on Ruby:

[http://www.rubycentral.com/book/](http://www.rubycentral.com/book/)

Jason
