From: Paul Brannan Date: 2001-09-19T00:42:51+09:00 Subject: [ruby-talk:21331] Re: nested require files need path internally > The big difference is C++ search done in compile time, Ruby search > done in run time (i.e. far more dangerous). But you can do > > require "./file.rb" > > at your own risk. > > matz. The problem with doing this is that if I have a directory structure like this: | +- foo | +- foo.rb | +- bar.rb | +- mystuff.rb And in mystuff.rb I have: require './foo/foo.rb' And in foo.rb I have: require './bar.rb' Then the require will fail, because bar.rb is not in the current directory. Additionally, part of the problem that was brought up was that if I do: require 'foo.rb' require 'foo' both of these will cause the same file to be required; the file will, in fact, be loaded twice. This is evident by the following simple program: if not defined?(x) then x = '' end x << './' require "#{x}#{__FILE__}" This will load the SAME FILE over 100 times. Ideally, require would do the following: 1) Check for the ./ prefix; if it is there, look in the same directory as __FILE__. 2) Check to see if the file is a symlink; if it is, get the name of the real file being required. Repeat as necessary. 3) Find the full pathname of the file being required before marking the file as already having been required. Paul