On Wed, 24 Mar 2004 11:32:47 +0900, Harry Ohlsen wrote:

> Is there an easy way to discover the path to a "require"-ed module (assuming it's a .rb file)?
> 
> Ie, is there some way to find out where the interpreter would find fred.rb if I said 
> 
>   require 'fred'
> 

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 



irb(main):001:0> require 'rextra'
../rextra.rb:126: warning: `*' interpreted as argument prefix
../rextra.rb:369: warning: `*' interpreted as argument prefix
(eval):4: warning: `*' interpreted as argument prefix
(eval):4: warning: `*' interpreted as argument prefix
(eval):4: warning: `*' interpreted as argument prefix
(eval):4: warning: `*' interpreted as argument prefix
(eval):4: warning: `*' interpreted as argument prefix
(eval):4: warning: `*' interpreted as argument prefix
=> true
irb(main):002:0> required
=> ["/home/neoneye/stow/ruby/lib/ruby/1.8/irb.rb", "/home/neoneye/stow/ruby/lib/ruby/1.8/e2mmap.rb", "/home/neoneye/stow/ruby/lib/ruby/1.8/irb/init.rb", "/home/neoneye/stow/ruby/lib/ruby/1.8/irb/context.rb", "/home/neoneye/stow/ruby/lib/ruby/1.8/irb/workspace.rb", "/home/neoneye/stow/ruby/lib/ruby/1.8/irb/extend-command.rb", "/home/neoneye/stow/ruby/lib/ruby/1.8/irb/ruby-lex.rb", "/home/neoneye/stow/ruby/lib/ruby/1.8/irb/slex.rb", "/home/neoneye/stow/ruby/lib/ruby/1.8/irb/ruby-token.rb", "/home/neoneye/stow/ruby/lib/ruby/1.8/irb/input-method.rb", "/home/neoneye/stow/ruby/lib/ruby/1.8/i386-freebsd5.1/readline.so", "/home/neoneye/stow/ruby/lib/ruby/1.8/irb/locale.rb", "/home/neoneye/stow/ruby/lib/ruby/1.8/tempfile.rb", "/home/neoneye/stow/ruby/lib/ruby/1.8/delegate.rb", "/home/neoneye/stow/ruby/lib/ruby/1.8/tmpdir.rb", "./rextra.rb", "/home/neoneye/stow/ruby/lib/ruby/1.8/i386-freebsd5.1/stringio.so"]
irb(main):003:0>


--
Simon Strandgaard