Run this in dofoo.rb (the launch file for your app):
$LOAD_PATH << File.expand_path(File.dirname(__FILE__))
···
-----Original Message-----
From: Nicholas Van Weerdenburg [mailto:nick@activehitconsulting.com]
Sent: Sunday, 18 July 2004 4:10 AM
To: ruby-talk ML
Subject: Ruby require path issues
How does one get $: to seamlessly include the directory of the parent
script?
I've written a library:
foo.rb
And a script,
dofoo.rb which does 'require "foo"'.
If I run dofoo.rb in it's own directory, require works. If I include
it's directory in my path, and run it from another directory, it can't
find the foo.rb library.
I've used $:.push("the path to my library") ( e.g.
$:.push(File.dirname($0)) ) before the require, which works but seems
inelegant.
Ultimately, I'd like to be able to distribute a set of scripts that any
user could drop into a path location.
Are there any other ways to do this (assuming no knowledge of the target
system)?
Thanks,
Nick