Stefano Crocco
6/24/2008 4:37:00 PM
On Tuesday 24 June 2008, Brad Hutchins wrote:
> This an odd one.
>
> require 'rubygems'
>
> works in my scripts . . . but if I go to IRB to test some 'rspec' stuff.
>
> I get:
> >> require 'rubygems'
>
> => false
>
>
> Tried including the whole path, but that did not work either any ideas
> why scripts being run don't have a problem requiring rubygems but IRB
> does?
>
>
> OSX 10.5.3
> Ruby 1.8.6
> Model Name: MacBook Pro 15"
> Model Identifier: MacBookPro1,1
> Processor Name: Intel Core Duo
> Processor Speed: 2.16 GHz
> Number Of Processors: 1
> Total Number Of Cores: 2
> L2 Cache: 2 MB
> Memory: 2 GB
The value returned by require doesn't tell whether there was an error or not
(if the file can't be found, a LoadError exception will be raised). Rather,
since require tries to avoid loading a file more than one time, it says
whether you required the file for the first time (true) or if it had already
been loaded (in this case returns false and doesn't try to load the file
again). So, the fact that in irb
require 'rubygems'
returns false only means that the file rubygems.rb had already been loaded,
and it wasn't necessary to load it a second time.
Stefano