Forum: Ruby $LOAD_PATH best practice?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Burdette Lamar (Guest)
on 2009-03-02 02:01
(Received via mailing list)
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
Tim H. (Guest)
on 2009-03-02 02:19
(Received via mailing list)
Burdette Lamar wrote:
> 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.
Nobuyoshi N. (Guest)
on 2009-03-02 11:31
(Received via mailing list)
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__)
BIl Kleb (Guest)
on 2009-03-02 12:25
(Received via mailing list)
Nobuyoshi N. wrote:
> Hi,

Hi.

> You don't need pathname.

I've never found a need for Pathname.

What is Pathname's purpose?

Regards,
This topic is locked and can not be replied to.