python python - 5 months ago 7
Ruby Question

get the ruby's required module path(or the gem path)at run-time

Well, I googled this problem but I could not find one which could give it a clear explanation.
I want to know is there a general way for detecting the loaded module path at run time, which includes both ruby code and c extension code?
If the $LOAD_PATH variable contains a lot of "Interface" modules which are defined in a lot of places, after calling "require 'Interface'", how can I tell which module is ruby using?
for example, both




has a gem named "Interface", after launching the rails, if a controller implements the class like

class MyCtrl < Interface

then how can I know which module is MyCtrl is using?


You can use reflection and use the source_location method.

Interface.public_methods().map{|m| Interface.public_method(m).source_location }.uniq