$: - where does it get its initial values?

Discussion in 'Ruby' started by Tuan Bui, Aug 6, 2003.

  1. Tuan Bui

    Tuan Bui Guest

    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
     
    Tuan Bui, Aug 6, 2003
    #1
    1. Advertising

  2. Tuan Bui

    Gennady Guest

    Re: - where does it get its initial values?

    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" <>
    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
    >
    >
    >
     
    Gennady, Aug 6, 2003
    #2
    1. Advertising

  3. Tuan Bui

    Ben Giddings Guest

    Re: - where does it get its initial values?

    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
     
    Ben Giddings, Aug 6, 2003
    #3
  4. Tuan Bui

    Marko Schulz Guest

    Re: - where does it get its initial values?

    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
     
    Marko Schulz, Aug 6, 2003
    #4
  5. Re: - where does it get its initial values?

    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 *
     
    Anders K. Madsen, Aug 6, 2003
    #5
  6. 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(".");
    }
     
    Brian Candler, Aug 6, 2003
    #6
  7. Tuan Bui

    Marko Schulz Guest

    Re: - where does it get its initial values?

    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
     
    Marko Schulz, Aug 6, 2003
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Markos Charatzas

    Hashtable with initial values

    Markos Charatzas, Feb 20, 2004, in forum: Java
    Replies:
    7
    Views:
    819
    Dale King
    Feb 23, 2004
  2. Leif K-Brooks
    Replies:
    5
    Views:
    329
    David Fraser
    Apr 15, 2005
  3. thunk
    Replies:
    1
    Views:
    315
    thunk
    Mar 30, 2010
  4. thunk
    Replies:
    0
    Views:
    487
    thunk
    Apr 1, 2010
  5. thunk
    Replies:
    14
    Views:
    625
    thunk
    Apr 3, 2010
Loading...

Share This Page