I have a class:
class TestClass
def method1
end
def method2
end
def method3
end
end
How can I get a list of my methods in this class (method1
, method2
, method3
)?
I have a class:
class TestClass
def method1
end
def method2
end
def method3
end
end
How can I get a list of my methods in this class (method1
, method2
, method3
)?
According to Ruby Doc instance_methods
Let's see the output.
You can get a more detailed list (e.g. structured by defining class) with gems like debugging or looksee.
or without all the inherited methods
(Was 'TestClass.methods - Object.methods')
You actually want
TestClass.instance_methods
, unless you're interested in whatTestClass
itself can do.Or you can call
methods
(notinstance_methods
) on the object:to get only methods that belong to that class only.
TestClass.instance_methods(false)
would return the methods from your given example (since they are instance methods of TestClass).