Ollivier Robert
8/28/2008 1:44:00 PM
In article <21639a804e467bb3f36669aab5b135fd@ruby-forum.com>,
Zhao Yi <youhaodeyi@gmail.com> wrote:
>My ruby script and module script are in the same directory. I print the
>$: variable and found the current directory "." is in there. But I
>always get the error: no such file to load.
Are you executing the script from the same directory? Having "." in RUBY_PATH only means that your "current" directory will be checked, not the one actually hosting the script.
If you are in "/tmp" and you have "/usr/local/lib/ruby:." in RUBY_PATH (aka $:) then, with bar.rb/foo.rb in $HOME
require "foo"
will make Ruby looking in "/usr/local/lib/ruby" and "/tmp", not in $HOME.
What you want is something like the following:
BASE_DIR = File.dirname(File.expand_path($0))
$: << BASE_DIR
require "foo"
Cheers,
--
Ollivier ROBERT -=- EEC/RIF/SEU -=-
Systems Engineering Unit