$: - where does it get its initial values?

T

Tuan Bui

Howdy,

Where does $: get its values from? The book says that it contains an
array of places to search for loaded files and that it is "initialized
to the list of standard directories, plus any additional ones you
specify using RUBYLIB and -I." Where does ruby get these standard
directories? I realize that I can set up RUBYLIB in my environment if I
want to search directories I specify, but I am mystified as to the
origin of the directories originally in $: . Any help would be welcome.

Thanks,
Tuan
 
G

Gennady

They are figured out during Ruby build by configure and then hardcoded into
the resulting executable. If your ruby is installed in /usr/local you can
check it with

$ strings /usr/local/bin/ruby | grep /usr/local
/usr/local/lib/ruby/site_ruby/1.6
/usr/local/lib/ruby/site_ruby/1.6/i686-linux
/usr/local/lib/ruby/site_ruby
/usr/local/lib/ruby/1.6
/usr/local/lib/ruby/1.6/i686-linux
/usr/local/bin:/usr/ucb:/usr/bin:/bin:.

Gennady.

----- Original Message -----
From: "Tuan Bui" <[email protected]>
Newsgroups: comp.lang.ruby
To: "ruby-talk ML" <[email protected]>
Sent: Wednesday, August 06, 2003 1:23 PM
Subject: $: - where does it get its initial values?
 
B

Ben Giddings

They are figured out during Ruby build by configure and then hardcoded into
the resulting executable. If your ruby is installed in /usr/local you can
check it with

$ strings /usr/local/bin/ruby | grep /usr/local
/usr/local/lib/ruby/site_ruby/1.6
/usr/local/lib/ruby/site_ruby/1.6/i686-linux
/usr/local/lib/ruby/site_ruby
/usr/local/lib/ruby/1.6
/usr/local/lib/ruby/1.6/i686-linux
/usr/local/bin:/usr/ucb:/usr/bin:/bin:.

This may have been the cause of problems I had when using ruby-mysql. My Ruby
binary was compiled for generic i386, but mysql was compiled for i686 so it
wanted to go in /usr/local/lib/ruby/site_ruby/i686-linux. The end result was
that I had an i386-linux and an i686-linux directory, but only one was being
searched. I got around that by using -I and/or setting an environment
variable... but it seems like it should be possible for Ruby to "figure this
out". Am I asking too much of it?

Ben
 
M

Marko Schulz

They are figured out during Ruby build by configure and then hardcoded into
the resulting executable. If your ruby is installed in /usr/local you can
check it with

$ strings /usr/local/bin/ruby | grep /usr/local
/usr/local/lib/ruby/site_ruby/1.6
:

How do you know, all strings with /usr/local in the ruby-executable
make up this path? Isn't easier, just to print out $: without any
-I or RUBYLIB?

$ (unset RUBYLIB; ruby -e 'p $:')
["/usr/local/lib/site_ruby/1.6", "/usr/local/lib/site_ruby/1.6/i386-linux", "/usr/local/lib/site_ruby", "/usr/lib/ruby/1.6", "/usr/lib/ruby/1.6/i386-linux", "."]
 
A

Anders K. Madsen

On Thu, 7 Aug 2003 05:57:33 +0900

[snip]
This may have been the cause of problems I had when using ruby-mysql. My
Ruby binary was compiled for generic i386, but mysql was compiled for i686 so
it wanted to go in /usr/local/lib/ruby/site_ruby/i686-linux. The end result
was that I had an i386-linux and an i686-linux directory, but only one was
being searched. [...]

Couldn't you have solved that by symlinking
/usr/local/lib/ruby/site_ruby/i686-linux to
/usr/local/lib/ruby/site_ruby/i386-linux?
 
B

Brian Candler

Where does $: get its values from? The book says that it contains an
array of places to search for loaded files and that it is "initialized
to the list of standard directories, plus any additional ones you
specify using RUBYLIB and -I." Where does ruby get these standard
directories?

In ruby.c, look for rb_load_path and calls to ruby_incpush; it is set from a
series of compile-time constants and/or environmnet variables.

if (rb_safe_level() == 0) {
ruby_incpush(getenv("RUBYLIB"));
}

#ifdef RUBY_SEARCH_PATH
ruby_incpush(RUBY_RELATIVE(RUBY_SEARCH_PATH));
#endif

ruby_incpush(RUBY_RELATIVE(RUBY_SITE_LIB2));
#ifdef RUBY_SITE_THIN_ARCHLIB
ruby_incpush(RUBY_RELATIVE(RUBY_SITE_THIN_ARCHLIB));
#endif
ruby_incpush(RUBY_RELATIVE(RUBY_SITE_ARCHLIB));
ruby_incpush(RUBY_RELATIVE(RUBY_SITE_LIB));

ruby_incpush(RUBY_RELATIVE(RUBY_LIB));
#ifdef RUBY_THIN_ARCHLIB
ruby_incpush(RUBY_RELATIVE(RUBY_THIN_ARCHLIB));
#endif
ruby_incpush(RUBY_RELATIVE(RUBY_ARCHLIB));

if (rb_safe_level() == 0) {
ruby_incpush(".");
}
 
M

Marko Schulz

This may have been the cause of problems I had when using ruby-mysql. My Ruby
binary was compiled for generic i386, but mysql was compiled for i686 so it
wanted to go in /usr/local/lib/ruby/site_ruby/i686-linux. The end result was
that I had an i386-linux and an i686-linux directory, but only one was being
searched. I got around that by using -I and/or setting an environment
variable... but it seems like it should be possible for Ruby to "figure this
out". Am I asking too much of it?

Even though you compile it for i686, the installer should know, that
he has to put it in /usr/local/lib/ruby/site_ruby/i386-linux. This is
AFAIK what mkmf.rb does, by using rbconfig: It queries the paths, ruby
was build with.
 

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
473,764
Messages
2,569,564
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top