仅查找我编写的自定义方法的方法,而不是任何继承的方法 (Ruby)
Method to find just my custom methods I wrote, not any inherited methods (Ruby)
class Foo
def initialize()
end
def cow
end
def dog
end
def any_other
end
end
我可以使用什么方法来查找我的自定义方法、cow、dog 和 any_other,而不是任何基本方法?
Foo.custom_methods
>>
:cow
:dog
:any_other
您可以使用 Foo.instance_methods(false)
获取实例方法,使用 Foo.methods(false)
获取 class 方法。
false
参数是说 不显示继承的方法。
class Foo
def initialize()
end
def cow
end
def dog
end
def any_other
end
end
我可以使用什么方法来查找我的自定义方法、cow、dog 和 any_other,而不是任何基本方法?
Foo.custom_methods
>>
:cow
:dog
:any_other
您可以使用 Foo.instance_methods(false)
获取实例方法,使用 Foo.methods(false)
获取 class 方法。
false
参数是说 不显示继承的方法。