On Tue, Mar 06, 2007 at 10:59:15PM +0900, Drew O. wrote:
It seems to me that if I create a module, a.rb, and a script that
require’s that module, b.rb, something interesting happens. In this
case, my a relies on other external files in the project, so I must
require these files within a.rb. However, I’ve noticed that because b
requires module a, all the require statements within the file a.rb must
be relative to b’s location in the directory structure.
No - they just have to be relative to any of the directories in $: (the
On my machine I get:
$ ruby1.8 -e ‘puts $:’
The last entry (.) means “the current directory”.
So if I do “require ‘a/b’” then the system will try
Thus, when these
files are stored in different places, it becomes very confusing when
looking at file a.rb as to why the require statements don’t seem to be
relative to that file. Is this intended functionality? Have I done
If you don’t want to install your own module files in one of the
listed above, then install them in some other directory and use
ruby -I /path/to/my/lib a.rb
to run the program; or else at the top of a.rb you can write
In both cases this just adds additional entries to the load path.