Ruby search

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

On Aug 24, 2006, at 11:54 AM, Henry S. 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.

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 G. II

Henry S. 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.