From: "trans. (T. Onoma)" Date: 2004-10-18T23:32:12+09:00 Subject: Re: Relative #require On Monday 18 October 2004 09:51 am, Gavin Kistner wrote: | I see that the (legacy) RCR 170[1] and [ruby-dev:22788] [2] (although I | can't read Japanese) have discussed this issue. Is there a better way | to handle this than working the hack mentioned in RCR170: | | dir = Pathname.new(File.expand_path(__FILE__)).realpath | require File.join(dir, 'utils' ) # UGLY | | into a new version of Kernel#require, which prepends the path if an | optional second parameter is true or something? Something like | (untested): | | class Kernel | alias_method :gk_old_require, :require | def require( path, local=nil ) | dir = local != :local ? '' : | Pathname.new(File.expand_path(__FILE__)).realpath | gk_old_require File.join( dir, path ) | end | end | | The key part (for me) is that files inside of code/k3/ be able to refer | to each other without having to know where they might be stored or have | been included from. Not sure if this is what you want, but a long time ago someone gave me this. module Kernel # Require files from same dir as running script. def import(*args) fd = File.dirname(caller[0]) args.each do |file_name| require File.join(fd, file_name) end end end Perhaps your hack is better? Nonetheless, the point being that it is preferable to have this as a separate method rather then integrated into #require. I recall that my experiments (also long ago) bore this out. T.