$LOAD_PATH best practice?

B

Burdette Lamar

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

Tim Hunter

Burdette said:
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.
 
N

Nobuyoshi Nakada

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

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,766
Messages
2,569,569
Members
45,043
Latest member
CannalabsCBDReview

Latest Threads

Top