我想知道如何列出模块中的所有方法,但不包括继承的方法.
如.
module Software
def exit
puts "exited"
end
end
puts Software.methods
将不仅列出exit,还列出所有继承的方法.
可以只列出出口吗?
谢谢
我想知道如何列出模块中的所有方法,但不包括继承的方法.
如.
module Software
def exit
puts "exited"
end
end
puts Software.methods
将不仅列出exit,还列出所有继承的方法.
可以只列出出口吗?
谢谢
事实上,Software.methods
会列出exit
.Software.instance_methods
将列出exit
以及任何继承的方法(在本例中,这算不了什么,因为除非包含另一个模块,否则模块不会继承任何方法).Software.instance_methods(false)
将只列出Software
中定义的方法.