Ruby search

H

Henry Savr

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
 
J

James Edward Gray II

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:
"
=> ["/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"]=> ["/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"]=> ["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
 
J

Joel VanderWerf

Henry said:
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.
 

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
474,210
Messages
2,571,091
Members
47,692
Latest member
RolandRose

Latest Threads

Top