Oct 212014
 

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)
 Posted by at 3:49 pm  Tagged with:

 Leave a Reply