Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > $: - where does it get its initial values?

Reply
Thread Tools

$: - where does it get its initial values?

 
 
Tuan Bui
Guest
Posts: n/a
 
      08-06-2003
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

 
Reply With Quote
 
 
 
 
Gennady
Guest
Posts: n/a
 
      08-06-2003
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" <>
Newsgroups: comp.lang.ruby
To: "ruby-talk ML" <ruby->
Sent: Wednesday, August 06, 2003 1:23 PM
Subject: $: - where does it get its initial values?


> 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
>
>
>



 
Reply With Quote
 
 
 
 
Ben Giddings
Guest
Posts: n/a
 
      08-06-2003
On Wed August 6 2003 4:33 pm, Gennady wrote:
> 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


 
Reply With Quote
 
Marko Schulz
Guest
Posts: n/a
 
      08-06-2003
On Thu, Aug 07, 2003 at 05:33:51AM +0900, Gennady wrote:
> 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", "."]

--
marko schulz

 
Reply With Quote
 
Anders K. Madsen
Guest
Posts: n/a
 
      08-06-2003
On Thu, 7 Aug 2003 05:57:33 +0900
Ben Giddings <> wrote:

[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?


--
* Anders K. Madsen * http://lillesvin.linux.dk *
* * Linux, Ruby, PHP and SQL *
 
Reply With Quote
 
Brian Candler
Guest
Posts: n/a
 
      08-06-2003
On Thu, Aug 07, 2003 at 05:23:35AM +0900, Tuan Bui wrote:
> 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(".");
}

 
Reply With Quote
 
Marko Schulz
Guest
Posts: n/a
 
      08-06-2003
On Thu, Aug 07, 2003 at 05:57:33AM +0900, Ben Giddings wrote:
>
> 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.

--
marko schulz

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Its a bird, its a plane, its.. um, an Attribute based System? thunk Ruby 14 04-03-2010 10:08 AM
Its a bird, its a plane, its.. um, an Attribute based System? thunk Ruby 0 04-01-2010 10:25 PM
Its a bird, its a plane, no ummm, its a Ruide thunk Ruby 1 03-30-2010 11:10 AM
Why does StringIO discard its initial value? Leif K-Brooks Python 5 04-15-2005 03:53 PM
Initial XP Page Does not Display Login Capability Mike Computer Support 8 01-24-2005 01:10 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57