On Jun 3, 2009, at 10:46 PM, Jason Lillywhite wrote:

> I noticed that some libraries (such as wx or gnuplot) need to have
>
> require 'rubygems'
>
> before the require of the actual library of interest. But some other
> libraries (such as gsl) do not require this. Can someone explain why
> this is the case?
>
> Thank you!

The most obvious reason to include rubygems is if you need some of the  
facilities provided by ... uh ... rubygems. But that's not the reason  
most code requires it. It turns out rubygems.rb is special because it  
is installed in /path/to/lib/ruby/site_ruby and its location in the  
filesystem is known to the interpreter. Where your actual gems are  
stored is normally in /path/to/lib/ruby/gems/maj.min/gems, but that's  
not mandatory. Say Ruby is installed in a directory to which you don't  
have write access. You would need to install your gems in a place  
where you do have write access, so you see that can't be known by the  
interpreter at build time.

At the point where you require (and execute, as a side effect)  
rubygems.rb, the GEM_HOME environment variable is used to puzzle out  
where gems might be. Some other options may also be explored. These  
are added to the load path so that requires on subsequent gems  
actually find the gems.

To answer your question more directly. If you need to require another  
gem, then you should require rubygems. If not, then you can make your  
code one line shorter.

Hope this helps explain.