From: dblack@... Date: 2003-01-12T10:38:51+09:00 Subject: Re: 'require' search path Hi -- On Sun, 12 Jan 2003, Tom Sawyer wrote: > On Saturday 11 January 2003 04:23 am, Tim Bates wrote: > > I wish 'require' would count the current directory as the directory the > > file is in, rather than the directory the script is being run from. > > wish granted: > > module Kernel > alias :require_basic :require > def require(file_or_directory) > if FileTest.directory?(file_or_directory) > require "#{file_or_directory}/#{file_or_directory}" > else > fp = File.dirname(File.expand_path(file_or_directory)) > $: << fp > r = require_basic file_or_directory > i = $LOAD_PATH.index(fp) > $LOAD_PATH.delete_at(i) if i > return r > end > end > end > > please test and improve upon. i have only done so minorly. notice also that it > adds my much wished for ability to auto-require things like 'dbi/dbi' just by > using 'dbi'. And seems to do away with the ability to require things like 'scanf' just by using 'scanf'.... candle:~/hacking/ruby$ ruby req.rb req.rb:10:in `require': No such file to load -- scanf/scanf (LoadError) from req.rb:10:in `require' from req.rb:6:in `require' from req.rb:18 In any event, I think it might be best to consider writing a new method, rather than overriding require, if you want to create a new package-loading functionality. 'require' and 'load' are spoken for, and you're going to end up quarantining your code from the rest of Ruby if you redefine them. David -- David Alan Black home: dblack@candle.superlink.net work: blackdav@shu.edu Web: http://pirate.shu.edu/~blackdav