Ruby search

(Henry Savr) #1

I want to manage the way how Ruby searches modules to load. I found,
that the $: variable is in charge, but it is read-only. Then I found
that RUBYLIB can be used to add directories.

As I have c:/PJ/lib and c:/PJ/test for my Windows souces I entered via
irb
RUBYLIB = ["c:/PJ/lib", "c:/PJ/test"] using the same Unix-style ("/"
instead of "\") as I saw in $:

When entered 'load "simple.rb"' I got "no such file to load".

How can I set RUBYLIB, or other variable to control the Ruby search?

PS. Changing slashes did not help

Thank you in advance

Henry

···

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

(James Edward Gray II) #2

I want to manage the way how Ruby searches modules to load. I found,
that the $: variable is in charge, but it is read-only.

Na, you can change it:

>> $: << "search_here_last
"
=> ["/usr/local/lib/ruby/site_ruby/1.8", "/usr/local/lib/ruby/site_ruby/1.8/i686-darwin8.5.2", "/usr/local/lib/ruby/site_ruby", "/usr/local/lib/ruby/1.8", "/usr/local/lib/ruby/1.8/i686-darwin8.5.2", ".", "search_here_last\n"]
>> exit
Firefly:~$ irb
>> $: << "search_here_last"
=> ["/usr/local/lib/ruby/site_ruby/1.8", "/usr/local/lib/ruby/site_ruby/1.8/i686-darwin8.5.2", "/usr/local/lib/ruby/site_ruby", "/usr/local/lib/ruby/1.8", "/usr/local/lib/ruby/1.8/i686-darwin8.5.2", ".", "search_here_last"]
>> $:.unshift("search_here_first")
=> ["search_here_first", "/usr/local/lib/ruby/site_ruby/1.8", "/usr/local/lib/ruby/site_ruby/1.8/i686-darwin8.5.2", "/usr/local/lib/ruby/site_ruby", "/usr/local/lib/ruby/1.8", "/usr/local/lib/ruby/1.8/i686-darwin8.5.2", ".", "search_here_last"]

James Edward Gray II

···

On Aug 24, 2006, at 11:54 AM, Henry Savr wrote:

(Joel VanderWerf) #3

Henry Savr wrote:

I want to manage the way how Ruby searches modules to load. I found, that the $: variable is in charge, but it is read-only. Then I found that RUBYLIB can be used to add directories.

The _variable_ is read only, but the _object_ that it refers to (an array of strings) is not frozen. You can modify the object:

irb(main):001:0> $: = 5
NameError: $: is a read-only variable
         from (irb):1
irb(main):002:0> $:.unshift "."
=> [".", "/usr/local/lib/ruby/site_ruby/1.8", "/usr/local/lib/ruby/site_ruby/1.8/i686-linux", "/usr/local/lib/ruby/site_ruby", "/usr/local/lib/ruby/1.8", "/usr/local/lib/ruby/1.8/i686-linux", "."]

Or you can use RUBYLIB to set $: for newly started ruby processes.

···

--
       vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407