R
Recheis Meinrad
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'
Von: Idan Sofer [mailto:[email protected]]
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]
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'
Von: Idan Sofer [mailto:[email protected]]
One of the things I most like in Ruby, is that even core functionality can behi,
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?
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]