This is a useful little trick to get all the methods that you can call on any Ruby object. This is extremely helpful when poking around someone else’s code (like Gem code) that is poorly documented.

foo.methods

This will return a long list of methods that you can call on the object. That list will include all the methods on all the superclasses of the object, including the Object object methods (the grandaddy of all objects). That’s often not very useful, so you can filter out the superclasses’s methods and only look at the methods associated with the subclass using:

foo.methods(false)

By Jason

Leave a Reply

Your email address will not be published. Required fields are marked *