From: Harry Ohlsen Date: 2004-03-24T12:53:23+09:00 Subject: Re: Ruby's module search path Simon Strandgaard wrote: > You may want to look at rextra.. I found this > > > def required > result = [] > $".each do |file| > $:.each do |path| > if File.exists?( path + '/' + file ) > result << (path + '/' + file) > next > end > end > end > result > end From the output, I'm guessing $" is the list of requires that have been executed so far? I couldn't find that one in Ruby In A Nutshell ... that's not to say it isn't in there, of course. I ended up with the following, which does a couple of other things. If you give the script no arguments, it displays a list of all .rb files in the search path. For any modules after a "-e" it invokes gvim (replace by your editor of choice). That does everything I need for now. Thanks to both you and Assaph for the help! ------------------------- def which(libname) $:.each do |d| f = File.join(d, libname) f += ".rb" return f if File.exists? f end nil end def list_modules # Find all the .rb files modules = {} $:.each do |d| Dir[d + "/*.rb"].each do |path| base = path.sub(/.*\//, "").sub(/\.rb/, "") modules[base] = path end end # Display them, sorted by module name maxWidth = 0 modules.keys.each do |mod| length = mod.length if length > maxWidth maxWidth = length end end modules.keys.sort.each do |mod| printf "%-*s %s\n", maxWidth, mod, modules[mod] end end if ARGV.length == 0 list_modules else edit = false ARGV.each do |mod| if mod == "-e" edit = true else if (path = which mod).nil? puts "Can't find module '#{mod}'" else if edit system "gvim #{path}" else puts path end end end end end