Detect the path used to require a file?

Hi all,

I'm having a problem in which a file is being required twice, using
slightly different paths, and I want to track down where this is
happening. Is there a way I can print out the path used to require a
given file?

Thanks!

Brian

···

--
Posted via http://www.ruby-forum.com/.

Create a load monitor, eg.

  alias old_require require
  def require(path)
    puts path, caller, "---"
    old_require(path)
  end

···

On Nov 30, 4:28 pm, Brian Hartin <brian.har...@pearson.com> wrote:

Hi all,

I'm having a problem in which a file is being required twice, using
slightly different paths, and I want to track down where this is
happening. Is there a way I can print out the path used to require a
given file?

I'm having a problem in which a file is being required twice, using
slightly different paths, and I want to track down where this is
happening. Is there a way I can print out the path used to require a
given file?

In most Ruby implementations the __FILE__ constant will be different depending on how the file was loaded. Notably, it will reflect the path used to load the file.

== test.rb ==
puts __FILE__

···

=============

> ruby -r test.rb -e ''
./test.rb

> ruby -r /home/user/temp/test.rb
/home/user/temp/test.rb

regards,
kaspar