From: Tom Sawyer Date: 2003-01-14T21:59:26+09:00 Subject: Re: 'require' search path On Tuesday 14 January 2003 02:34 am, Tobias Peters wrote: > Here's a test that fails: ... quite right! thanks Tobias! my solution failed to take into consideration the initial directory offset of the running process, thus running: "ruby testerequire/file1.rb" would not catch the testrequire directory on the first call to require and fail subsequently. so, i have taken your #import solution, using caller[0], and mixed it with mine, plus a touch of clean up. let's see if this does the trick: alias :require_basic :require def require(file_or_directory) begin fp = File.expand_path(File.dirname(caller[0])) $: << fp r = require_basic file_or_directory i = $:.index(fp) $:.delete_at(i) if i return r rescue if FileTest.directory?(file_or_directory) require "#{file_or_directory}/#{file_or_directory}" else raise end end end notice that, on the recommendation of David, i made the "directory require" portion only happen if all else fails. so hopefully this covers all contingencies now while being backward compatable (on the whole). even so, i bet it can still be cleaned up a bit more. what's your take? -- tom sawyer, aka transami transami@transami.net .''. .''. . *''* :_\/_: . :_\/_: _\(/_ .:.*_\/_* : /\ : .'.:.'. .''.: /\ : ./)\ ':'* /\ * : '..'. -=:o:=- :_\/_:'.:::. | ' *''* * '.\'/.' _\(/_'.':'.' : /\ : ::::: = *_\/_* -= o =- /)\ ' * '..' ':::' === * /\ * .'/.\'. '._____ * | *..* : |. |' .---"| * | _ .--'| || | _| | * | .-'| __ | | | || | .-----. | |' | || | | | | | || | ___' ' /"\ | '-."". '-' '-.' '` |_. ------------------------------------------------------------