require rubygems

E

eva54321

Hi,

I saw people wrote "require 'rubygems'" in their scripts sometime.
For what purpose is this module used? Thanks.

-eva
 
J

Josh Cheek

[Note: parts of this message were removed to make it a legal post.]

Hi,

I saw people wrote "require 'rubygems'" in their scripts sometime.
For what purpose is this module used? Thanks.

-eva
In Ruby, libraries (sets of code you can use in your program that other
people wrote) are called gems. Most people use Rubygems to manage their
gems, such as installing, uninstalling, installing specific versions, etc
(see rubygems.org)

For some annoying reason that has to do with the load path, Ruby can't find
the gems you have installed unless you first require rubygems. So people who
want to use those gems will require rubygems in their file before requiring
the gem itself, so that the gem loads correctly. The alternative is to set
some environment variable.
$ RUBYOPT="rubygems"
$ export RUBYOPT
$ ruby FOO.rb

But really, you'd want to put that in your .profile so you don't have to
explicitly do it every time you open a terminal window.
In ruby 1.9, rubygems are apparently loaded by default, or the path is
modified, or something such that you don't have to worry about it anymore.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top