hi,
i found a hack like this and hoped that someone would come up with something more elegant
but, wow. this is definitely much dirtier.
this is my hack( according to my considered example):
in lib.rb:
$libpath=(FILE).sub Regexp.new(File.basename( FILE ) ), ‘’
require $libpath+‘annother.rb’
hi,
but i am not very pleased with it. the library in the directory lib, must
not know from where it is required. what can i do so that lib can require
all it’s files no matter where the script that requires lib.rb is located?
One of the things I most like in Ruby, is that even core functionality can be
easily modified at run-time:
[start messy untested code]
alias :_oldrequire :require
def require(req)
if req=~///
splited=req.split(‘/’)
req_file=splited.pop
req_path=splited.join(‘/’)
oldpath=Dir.pwd
Dir.chdir req_path
ret=_oldrequire(req_file)
Dir.chdir oldpath
return ret
else
_oldrequire(req)
end
end
[end messy untested code]
···
Von: Idan Sofer [mailto:idan@idanso.dyndns.org]
On Tuesday 09 September 2003 16:20, Recheis Meinrad wrote: