-1
例如,我有这样的代码:红宝石:我怎样才能找到模块的所有类方法
module ExampleModule
def self.module_method
end
def normal_method
end
end
如果我尝试致电ExampleModule.instance_methods
,我只能看到normal_method
。找遍了也singleton_class
但看起来像Ruby没有把类方法中singleton class
:
ExampleModule.singleton_class.each do |method|
print method
end
怎么能看到self.module_method
(只有这个方法,模块ExampleModule的不是其他父类的方法)。
感谢
'ExampleModule.methods' – trueinViso
我不会称之为 “元编程”。这只是使用普通的'send'。 –
@trueinViso但它会显示所有的方法。我只想在这个模块中只显示自定义的方法。 –