Path to loaded module ?

J

Jonathan DERROUGH

Hello,

Is there any way to get the path of a loaded module ?
I think I have two concurent versions of the same module and I can't
figure which one is loaded.

Thx,
Jonathan.
 
R

Robert Klemme

Jonathan DERROUGH said:
Hello,

Is there any way to get the path of a loaded module ?
I think I have two concurent versions of the same module and I can't
figure which one is loaded.

Thx,
Jonathan.

If you can modify them the easiest is probably to insert a line like

puts __FILE__

into those modules.

You can as well use $: (an array of directories) to determine which of the
two appears first in your load path. HTH

Yet another option is to use set_trace_func to view code execution:

ruby -e 'set_trace_func lambda {|*a| puts a[1]}; require "your_module"}'

This will print the file name of each trace event and you see which is
loaded.

Kind regards

robert
 
R

Ryan Leavengood

Here is something to try:

def script_find(name)
name +=3D '.rb.' if name !~ /\.rb$/
$LOAD_PATH.inject([]) do |result, path|
if test(?e, File.join(path, name))
result << path
end
result
end
end
p script_find('singleton')

Ryan
 

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

No members online now.

Forum statistics

Threads
474,430
Messages
2,571,676
Members
48,796
Latest member
Greg L.

Latest Threads

Top