$LOAD_PATH best practice?

Discussion in 'Ruby' started by Burdette Lamar, Mar 1, 2009.

  1. [Note: parts of this message were removed to make it a legal post.]

    The local filetree corresponding to source control is not in the same location on all machines.

    Therefore, the needed Ruby $LOAD_PATH varies from one machine to another.

    I can control this from a script of course. I can, for example, addthis to the top of a script that's two levels below the 'root':

    require 'pathname'
    home_path = Pathname.new(File.join(File.dirname(__FILE__), '../..')).realpath
    $LOAD_PATH.push home_path unless ($LOAD_PATH.index(home_path))

    This works, but is it best? Is there best practice for this sort ofthing?

    Thanks, Burdette
    Burdette Lamar, Mar 1, 2009
    #1
    1. Advertising

  2. Burdette Lamar

    Tim Hunter Guest

    Burdette Lamar wrote:
    > The local filetree corresponding to source control is not in the same location on all machines.
    >
    > Therefore, the needed Ruby $LOAD_PATH varies from one machine to another.
    >
    > I can control this from a script of course. I can, for example, addthis to the top of a script that's two levels below the 'root':
    >
    > require 'pathname'
    > home_path = Pathname.new(File.join(File.dirname(__FILE__), '../..')).realpath
    > $LOAD_PATH.push home_path unless ($LOAD_PATH.index(home_path))
    >
    > This works, but is it best? Is there best practice for this sort ofthing?
    >
    > Thanks, Burdette
    >
    >
    >
    >


    You can also modify the load path by setting the RUBYLIB environment
    variable, or by using the -I option on the command line. Since the load
    path is constant on a machine, I'd argue for setting RUBYLIB instead of
    modifying every script.

    --
    RMagick: http://rmagick.rubyforge.org/
    Tim Hunter, Mar 2, 2009
    #2
    1. Advertising

  3. Hi,

    At Mon, 2 Mar 2009 08:58:46 +0900,
    Burdette Lamar wrote in [ruby-talk:330039]:
    > require 'pathname'
    > home_path = Pathname.new(File.join(File.dirname(__FILE__), '../..')).realpath


    You don't need pathname.

    home_path = File.expand_path('../../..', __FILE__)

    --
    Nobu Nakada
    Nobuyoshi Nakada, Mar 2, 2009
    #3
  4. Burdette Lamar

    BIl Kleb Guest

    BIl Kleb, Mar 2, 2009
    #4
    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. Replies:
    3
    Views:
    169
    Hal Fulton
    Aug 31, 2004
  2. Replies:
    0
    Views:
    84
  3. Stephen Tashiro

    A good system for $LOAD_PATH management?

    Stephen Tashiro, Mar 31, 2006, in forum: Ruby
    Replies:
    6
    Views:
    118
    Trans
    Apr 4, 2006
  4. Daniel Harple
    Replies:
    2
    Views:
    123
  5. veer
    Replies:
    0
    Views:
    79
Loading...

Share This Page