Zhao Yi wrote:
> c.rb:
> 
> require File.dirname(__FILE__)+'/a.rb'

That's the source of the problem.

The solution is to set up $LOAD_PATH appropriately at the start of your 
program, so that you never have to do require with an absolute path.

For example, let's say you have the following directory structure for 
your project:

  bin/foo
  bin/bar
  lib/a
  lib/b
  lib/c

Stick the following at the top of bin/foo and bin/bar:

#!/usr/bin/ruby -w
$LOAD_PATH.unshift File.dirname(__FILE__)+"/../lib"

From this point onwards you can do require 'a', require 'b' etc without 
any absolute paths. This also has the advantage that it doesn't matter 
what the current directory is when you start the program. e.g. you can 
do

$ cd /tmp
$ /home/me/bin/foo

and it will work as expected.

Hints:

- When running scripts from the command line, you can use -Ilib to get 
the 'lib' dir added to the load path.

- If you're playing with Rails, look at config/boot.rb
-- 
Posted via http://www.ruby-forum.com/.