List of instance methods of current class only
ruby
Solution
You can use the method `Module#instance_methods`:
o.class.instance_methods(false)
Warning The documentation seems to be wrong, it says that:
With no argument, or with an argument that is false, the instance methods in mod are returned, otherwise the methods in mod and mod’s superclasses are returned.
But actually the parameter by default is `true`:
String.instance_methods.size
# => 184
String.instance_methods(false).size
# => 130
Problem
I have an instance `o` of class `O`. I'd like to know what `o` is capable of. `o.methods` will give me many methods. So I usually do `o.methods - Object.instance_methods`. But that is not concise. I want to do something like `o.methods - o.class.superclass.instance_methods`. That is, just the methods defined in `O` itself. Is there some other way?