Hi,

In message "[ruby-talk:21353] Re: nested require files need path internally"
    on 01/09/19, Paul Brannan <pbrannan / atdesk.com> writes:

|> I'm not sure what is your point.  If you really want to read from the
|> current directory hierarchy (which is pretty unreliable), you can
|> prepend "." to $LOAD_PATH variable.
|
|The idea is that I want to split a project between multiple files.

I think we are talking different issues.  You're talking about a
program that spans multiple files.  I'm talking about the danger of
loading from the current directory.  If your program contains

  require './foo.rb'

and what if the program is invoked in a directory that you don't
expect, and that happend to contain the file named foo.rb, and that
foo.rb has the following line?

  system "rm -rf $HOME"

So forget about the current directory.  Multiple files should be read
from the absolute directory.  I recommend you to prepend application
specific directory to the $LOAD_PATH in the main file.

|Now consider that Foo inherits from or otherwise depends on Bar.  Then in
|Foo.rb, I'm likely to put:

<snip>

You don't have this kind of problem, if you don't try to load from the
current directory.

|It's not just about loading from the CWD.  On my machine,
|/usr/local/lib/ruby/1.6 is already cluttered with a number of files.  I
|can easily add new directories, which is fine (e.g. with 'net/ftp' et
|al.), but what if a script in the 'net' directory wants to load another
|script from the 'net' directory?  It doesn't really make sense for that
|script to have to require 'net/foo', since that requires the script to
|know where it is placed (or to deduce that information).

Why not?  It's the way library files are loaded.  The use of relative
loading path may reduce the information, but results weakness.  Too
less information makes human confusing.  For example, using your
scheme, if you meet

  require 'foo'

you have to look around directories, first the directory that calling
file resides, then the current directory, and so on.  In addition,
this might varies time to time according to runtime environment.
I don't feel it's good.

|Since require is not an operation that is performed often, it makes sense
|to me to make checks 2) and 3), since they are likely to make code more
|robust.

I'm not sure how much difference they would make.  Especially following
symlinks.

							matz.