[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

why 1.hour doesn't work?

SpringFlowers AutumnMoon

7/2/2007 11:29:00 AM

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?

--
Posted via http://www.ruby-....

5 Answers

dblack

7/2/2007 11:37:00 AM

0

SpringFlowers AutumnMoon

7/2/2007 11:42:00 AM

0


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

So is there a way to have all that's in Rails also available in Ruby?
(or at least for 1.hour and 1.hour.from_now )


Pierre-Charles David

7/2/2007 11:43:00 AM

0

2007/7/2, Kenneth <summercoolness@gmail.com>:
> 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

--
http://pc...

Kenneth Ll

7/2/2007 9:56:00 PM

0


> % 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...)

--
Posted via http://www.ruby-....

Tim Hunter

7/2/2007 10:05:00 PM

0

Kenneth Ll wrote:
>> % 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...)
>
>
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.

--
RMagick OS X Installer [http://rubyforge.org/project...]
RMagick Hints & Tips [http://rubyforge.org/forum/forum.php?for...]
RMagick Installation FAQ [http://rmagick.rubyforge.org/instal...]