Reputation: 1093
I haven been all day training to fix this problem but i couldn't.
The question is easy, i don't want to put anymore the require 'rubygems' line everytime i require a gem...
If i put the require 'rubygems' before any other "require" the file runs perfect but if i don't put the require 'rubygems' line the following error occurs:
(...)in `require': no such file to load -- 'gemname' (LoadError)
I suspect that may be there is some path remaining where to check out the gems repository.
I want to ask you if there is a way to do this.
Thanks a lot.
Cheers, Juan.
Upvotes: 4
Views: 14390
Reputation: 4753
put
require 'rubygems'
as first line of your ruby code and be safe. of course you can invoke with -rubygems switch (as Peter Krenn wrote) instead of it
Upvotes: 5
Reputation: 31428
In Unix you can:
$ RUBYOPT="rubygems"
$ export RUBYOPT
$ ruby juans_masterpiece.rb
and in Windows:
SET RUBYOPT=rubygems
or right-click on My Computer->Properties->Advanced->Environment Variables
and then finally add the RUBYOPT variable there. Next time you open a cmd.exe run set
and it will be there.
Upvotes: 3
Reputation: 28362
Right-click the Computer Icon, then select Properties, then Additional system parameters, then Environment variables, there is a GUI for changing opts, click Create, put name and value, OK. This is an approximate translation of how you do this on windows 7, if you can't find the place try to google for "changing environment variables in {your windows version here}"
Upvotes: 0
Reputation: 237060
You don't have to put it every time you require a gem — you just have to have it before the first time you require a gem. When you require Rubygems, it replaces the default require with a special one that does all the Rubygems magic.
But that's only in 1.8. You don't have to require Rubygems at all in Ruby 1.9 — so that's a very easy solution to the problem as long as you aren't dependent on 1.8-specific things.
Upvotes: 2
Reputation: 397
You could invoke you ruby script with
ruby -rubygems script.rb
or add rubygems to RUBYOPT
$ export RUBYOPT="rubygems"
Upvotes: 18