# Ruby search

**URL:** <https://www.ruby-forum.com/t/ruby-search/66311>\
**Category:** Ruby\
**Created:** [August 24, 2006, 6:54pm UTC](https://www.ruby-forum.com/t/ruby-search/66311 "2006-08-24T18:54:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![henrys](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/3d9bf3/32.png) [@henrys](https://www.ruby-forum.com/u/henrys)\
**Post date:** [August 24, 2006, 6:54pm UTC](https://www.ruby-forum.com/t/ruby-search/66311/1 "2006-08-24T18:54:51Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![henrys](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/3d9bf3/32.png) [@henrys](https://www.ruby-forum.com/u/henrys)\
**Post date:** [August 24, 2006, 7:52pm UTC](https://www.ruby-forum.com/t/ruby-search/66311/2 "2006-08-24T19:52:43Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![henrys](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/3d9bf3/32.png) [@henrys](https://www.ruby-forum.com/u/henrys)\
**Post date:** [August 24, 2006, 8:22pm UTC](https://www.ruby-forum.com/t/ruby-search/66311/3 "2006-08-24T20:22:48Z")

</div>

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.
