Setting RUBYLIB

S

Stu Glaser

Hi,

I currently have a project with two files. I want to include one file
from the other without specifying the entire path. Here's what I'm
trying to do:

File: ./app/control/first.rb
puts "HELLO"

File: ./main.rb
ENV['RUBYLIB'] = "./app"
require 'control/first.rb'

However, it refuses to find the script ('require': No such file to load
-- control/first.rb)

When I set RUBYLIB from the (bash) shell, the program runs correctly.
How can I set it inside the main ruby program?

Thanks,
-Stu Glaser
 
S

Stefan Lang

Hi,

I currently have a project with two files. I want to include one
file from the other without specifying the entire path. Here's
what I'm trying to do:

File: ./app/control/first.rb
puts "HELLO"

File: ./main.rb
ENV['RUBYLIB'] = "./app"
require 'control/first.rb'

However, it refuses to find the script ('require': No such file to
load -- control/first.rb)

When I set RUBYLIB from the (bash) shell, the program runs
correctly. How can I set it inside the main ruby program?

The RUBYLIB environment variable is read by the ruby interpreter
only at startup.
Use this:

$LOAD_PATH.unshift "app"
require ....

More robust would be to use an absolute path:

$LOAD_PATH.unshift(File.join(File.dirname(File.expand_path(__FILE__)),
"app"))
require ...

HTH,
Stefan
 
N

nobu.nokada

Hi,

At Sat, 5 Nov 2005 05:19:40 +0900,
Stu Glaser wrote in [ruby-talk:164235]:
File: ./main.rb
ENV['RUBYLIB'] = "./app"
require 'control/first.rb'

However, it refuses to find the script ('require': No such file to load
-- control/first.rb)

RUBYLIB is for -S option, but not concerned with 'require'.
 
N

nobu.nokada

Hi,

At Sat, 5 Nov 2005 09:11:40 +0900,
File: ./main.rb
ENV['RUBYLIB'] = "./app"
require 'control/first.rb'

However, it refuses to find the script ('require': No such file to load
-- control/first.rb)

RUBYLIB is for -S option, but not concerned with 'require'.

Sorry, I confused it with RUBYPATH.
 
S

Stu Glaser

Thanks Stefan! That was exactly what I was looking for.

-Stu
P.S. ActiveRecord is awesome!
 

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,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top