From: Tom Sawyer Date: 2003-01-22T13:50:19+09:00 Subject: Re: 'require' search path On Tuesday 14 January 2003 05:59 am, Tom Sawyer wrote: > 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 > i have just run into a potential conflict. i named a file to require 'DBI.rb'. of course the problem with this is that it could require the typical DBI library rather than my file. (actually not in this case but it becomes conceivable in other cases) of course i could rename my file to avoid such a conflict, but that means being very aware of the fact that DBI (or other lib) exists. so i have taken up the alternate suggestion: def import(file_name) require File.join(File.dirname(caller[0]), file_name) end alias :require_basic :require def require(file_or_directory) begin require_basic file_or_directory rescue if FileTest.directory?(file_or_directory) require "#{file_or_directory}/#{file_or_directory}" else raise end end end -- tom sawyer, aka transami transami@transami.net .''. .''. . *''* :_\/_: . :_\/_: _\(/_ .:.*_\/_* : /\ : .'.:.'. .''.: /\ : ./)\ ':'* /\ * : '..'. -=:-:=- :_\/_:'.:::. | ' *''* * '.\'/.' _\(/_'.':'.' : /\ : ::::: = *_\/_* -= * =- /)\ ' * '..' ':::' === * /\ * .'/.\'. '._____ * | *..* : |. |' .---"| * | _ .--'| || | _| | * | .-'| __ | | | || | .-----. | |' | || | | | | | || | ___' ' /"\ | '-."". '-' '-.' '` |_. ------------------------------------------------------------