在 运行 时获取 ruby 所需的模块路径(或 gem 路径)
get the ruby's required module path(or the gem path)at run-time
好吧,我用 google 搜索了这个问题,但找不到可以给出明确解释的内容。
我想知道有没有一种通用的方法来检测在 运行 时间加载的模块路径,其中包括 ruby 代码和 c 扩展代码?
如果 $LOAD_PATH 变量包含很多 "Interface" 模块,这些模块定义在很多地方,在调用 "require 'Interface'" 之后,如何判断 ruby 使用了哪个模块?
例如,
/web/blogplus/lib
和
/web/blogplus/vendor
有一个名为 "Interface" 的 gem,在启动 rails 之后,如果控制器实现了 class,比如
class MyCtrl < Interface
end
那我怎么知道MyCtrl使用的是哪个模块呢?
可以使用反射,使用source_location
方法。
Interface.public_methods().map{|m| Interface.public_method(m).source_location }.uniq
好吧,我用 google 搜索了这个问题,但找不到可以给出明确解释的内容。 我想知道有没有一种通用的方法来检测在 运行 时间加载的模块路径,其中包括 ruby 代码和 c 扩展代码? 如果 $LOAD_PATH 变量包含很多 "Interface" 模块,这些模块定义在很多地方,在调用 "require 'Interface'" 之后,如何判断 ruby 使用了哪个模块? 例如,
/web/blogplus/lib
和
/web/blogplus/vendor
有一个名为 "Interface" 的 gem,在启动 rails 之后,如果控制器实现了 class,比如
class MyCtrl < Interface
end
那我怎么知道MyCtrl使用的是哪个模块呢?
可以使用反射,使用source_location
方法。
Interface.public_methods().map{|m| Interface.public_method(m).source_location }.uniq