我想知道如何列出模塊中的所有方法,但不包括繼承的方法。僅在模塊中列出方法?
例如。
module Software
def exit
puts "exited"
end
end
puts Software.methods
將列出不僅退出,但所有繼承的方法。
可以列出退出嗎?
感謝
我想知道如何列出模塊中的所有方法,但不包括繼承的方法。僅在模塊中列出方法?
例如。
module Software
def exit
puts "exited"
end
end
puts Software.methods
將列出不僅退出,但所有繼承的方法。
可以列出退出嗎?
感謝
其實Software.methods
將不是列表exit
。 Software.instance_methods
將列出exit
以及任何繼承的方法(在這種情況下沒有什麼是因爲模塊不會繼承任何方法,除非包含另一個模塊)。 Software.instance_methods(false)
將只列出在Software
中定義的方法。
Software.public_instance_methods
似乎爲你的榜樣工作。