Detect the path used to require a file?

B

Brian Hartin

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
 
I

Intransition

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. =A0Is there a way I can print out the path used to require a
given file?

Create a load monitor, eg.

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

Kaspar Schiess

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,754
Messages
2,569,525
Members
44,997
Latest member
mileyka

Latest Threads

Top