我有一个模块MyModule
.我动态地将类加载到其中.如何获取在其命名空间中定义的类的列表?
例子:
def load_plugins
Dir.glob(File.dirname(__FILE__) + '/plugins/*.rb') do |f|
MyModule.class_eval File.read(f)
end
# now how can I find the new classes I've loaded into MyModule?
end
我应该说,每f
个都包含类似"class Foo;end"的内容.
您也可以这样想:在Rails中,如何通过编程找到ActiveRecord模块中定义的所有类?