From: Dave Burt Date: 2005-09-09T18:26:30+09:00 Subject: Re: 'which' command for Ruby (like csh which?) Dan Bikle asked: > suppose I have, > > require "redgreenblue" > in > runme.rb > > 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 Cheers, Dave