From: Gavin Sinclair Date: 2003-11-24T21:44:29+09:00 Subject: Re: Library path relative to current .rb file On Monday, November 24, 2003, 8:02:12 PM, Zoran wrote: > One of the most irritating (missing) features of Ruby is inability to > 'require' files in the same directory or subdirectories as the > executing source file. In other programming languages (Java, C, C++) > that is commonly used. Note that this is different from the current > woriking directory. Agreed. > [...] > The solution is to prepend current file's directory before every > 'require', which is very ugly. > require File.join(File.dirname(__FILE__), 'utils' ) # UGLY It's a lot less ugly if you separate the ugly stuff into a variable first. require 'pathname' # 1.8 this_dir = Pathname.new(File.dirname(__FILE__)) require this_dir + "utils.rb" > My question is: > - Why aren't required files looked up in subdirectories relative to > the current file? Well, they dhould use $LOAD_PATH, shouldn't they? Perhaps you mean another syntax. > - Is there an easy way to simulate that in Ruby? No. > - Can it be easily fixed in Ruby interpreter source code? Probably. Adding syntax is easy of you know what you're doing (I don't), but it's controversial at this stage of Ruby's life. Search for an RCR (www.rubygarden.org) on it; create a new one if there is none. Personally, although I have occasionally wanted what you want, I don't think I've (in recent times) ever actually used the __FILE__ trick for 'require'. It's more a case of taking a look at how files/directories are laid out. I'll have plenty of specific advice if you detail what you're trying to do :) Cheers, Gavin