[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Path to loaded module ?

Jonathan DERROUGH

1/15/2006 4:53:00 PM

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.

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


2 Answers

Robert Klemme

1/15/2006 5:26:00 PM

0

Jonathan DERROUGH <jonathan.derrough@no-log.org> wrote:
> 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

Ryan Leavengood

1/17/2006 8:59:00 PM

0

Here is something to try:

def script_find(name)
name += '.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

On 1/15/06, Jonathan DERROUGH <jonathan.derrough@no-log.org> wrote:
> 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.