Given any object I can call #public_methods
and see all the methods it will respond to. However, I find it would sometimes be handy to get a quick list of all the public methods that are not inherited, i.e. the stuff that's really part of this class.
I found in "Easy way to list public methods for a Ruby object" that if I use:
(Foo.public_methods - Object.public_methods).sort
I can filter out a lot of basic Ruby stuff. I'd like to be able to filter everything that was inherited all the way up the chain. If I know the parent class I can filter using it, but I'd like to come up with a generic command that could return an array of the uninherited public methods for any object.
Just pass
false
for theinherited
argument ofpublic_methods
:Not an answer to your question, but in case you didn't know,
irb
does autocompletion, so it's easy to get the list of public methods (especially if you know the beginning of the method you are looking for). Just hit tab; hitting it twice will list all possibilities (including inherited ones, though):Using
pry
makes it even easier to see the methods available, broken down by level of inheritance: