Is there a way I can tell which
redgreenblue.rb file will get pulled in to runme.rb
at run time?
I don't know of anything built in, but this should do the trick:
def which(lib)
lib += ".rb" unless lib[-3..-1] == ".rb"
$LOAD_PATH.each do |path|
file = File.join(path, lib)
return file if FileTest.exist?(file)
end
if defined? Gem @gempath_searcher ||= Gem::GemPathSearcher.new
if spec = @gempath_searcher.find(lib) and lib = spec.autorequire
lib += ".rb" unless lib[-3..-1] == ".rb"
spec.require_paths.each do |path|
file = File.join(spec.full_gem_path, path, lib)
return file if FileTest.exist?(file)
end
end
end
nil
end
glob_for = lambda do |stem|
glob = "%s{,%s,%s}" % [stem, dl_ext, rb_ext]
Dir[glob].each do |path|
throw 'which', path if pat.match(path) and test(?r, path)
end
end
File::expand_path(
catch('which') do
if lib.absolute?
glob_for[ lib ]
else
search_path.each{|dir| glob_for[ File::join(dir, lib) ]}
end
return nil
end
)
end
p which_lib('session')
p which_lib('pty.so')
p which_lib(File::expand_path(__FILE__))
p which_lib('fubar')
Is there a way I can tell which
redgreenblue.rb file will get pulled in to runme.rb
at run time?
Most UNIX shells have a 'which' builtin command which
offers similar behavior.
If I type
which runme
the builtin which command will tell which runme file
the shell would run should I choose to run it.
Thanks.
-Dan
--
email :: ara [dot] t [dot] howard [at] noaa [dot] gov
phone :: 303.497.6469
Your life dwells amoung the causes of death
Like a lamp standing in a strong breeze. --Nagarjuna