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
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
···
On Friday 04 November 2005 21:19, Stu Glaser wrote:
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?
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'.
···
--
Nobu Nakada
Hi,
At Sat, 5 Nov 2005 09:11:40 +0900,
nobu.nokada@softhome.net wrote in [ruby-talk:164289]:
> 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.
···
--
Nobu Nakada
Thanks Stefan! That was exactly what I was looking for.
-Stu
P.S. ActiveRecord is awesome!
Stefan Lang wrote:
···
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