On Tue, Oct 19, 2004 at 01:25:41AM +0900, Brian Candler wrote:
> A simple solution might be something like this:
> 
>   $:.push File.dirname(File.expand_path(__FILE__))

This solution is too naive, unfortunately.  Consider this program:

main.rb:

$:.push File.dirname(File.expand_path(__FILE__))
require 'helper/foo'
rqeuire 'helper/bar'

helper/bar.rb:

$:.push File.dirname(File.expand_path(__FILE__))
puts "bar.rb"
require 'foo'

helper/foo.rb:

$:.push File.dirname(File.expand_path(__FILE__))
puts "foo.rb"

[pbrannan@zaphod tmp]$ ruby main.rb
foo.rb
bar.rb
foo.rb

There are three workarounds I know of:
1. foo.rb and bar.rb must know about the directory structure they are
   in, and bar.rb must require 'helper/foo'
2. main.rb can add the 'helper' directory to $:, and require foo.rb and
   bar.rb as if they were standalone libraries
3. The filenames can be normalized before storing them in $" (see
   RCR#211).  This can be combined with the 'requirelocal' method which
   requires a file from the same directory as it is located (search the
   mailing list archives for more details).

Paul