From: Gavin Kistner Date: 2004-10-18T22:51:06+09:00 Subject: Relative #require I want relative require paths, in addition to 'absolute': app/run.rb app/code/app.rb app/code/k1.rb app/code/k2.rb app/code/k3/k3.rb app/code/k3/k4.rb app/code/lib/foo.rb % cat run.rb require 'code/app' $app = App.instance $app.run % cat code/app.rb require 'k1'; require 'k2'; require 'k3/k3' #RELATIVE % cat code/k1.rb require 'lib/foo.rb' #RELATIVE % cat code/k3/k3.rb require 'k4' #RELATIVE % cat code/k3/k4.rb require 'code/lib/foo.rb' #~ABSOLUTE 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. [1] http://rcrchive.net/rcr/RCR/RCR170 [2] http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-dev/22788 -- (-, /\ \/ / /\/