Unify Method List Introspection?
Although Ruby has many core methods for retrieving the list of methods available to an object, or to the instances of a class, I believe they have gotten a little confusing (also see):
Module#instance_methodsdo not include private methods (at the same time they do include protected ones). There is already
Object#protected_methods) for distinguishing visibility scope , but no way to get all methods of an object.
- There is the inconsistency that in most cases the argument being passed to
*_methodsmethods let's you decide if you want to consider the inheritance chain, or not - But the prominent exception is
Object#methodswhich instead toggles inheritance to singleton only! (for which we also have
- There is no direct API for getting a list of private singleton methods
Now that we have keyword arguments, we could provide a single API for listing methods. One way of doing so could be the Object#shadow's methods method. Having a keyword arguments based API would allow users to specify the dimensions of their requests better - should it:
- return the object's methods, or methods of its instances?
- return only methods of a specific visibility scope?
- return only methods of a specific inheritance level (e.g. only singleton, or all the way down to
What do you think about having one unified way for retrieving an object's method list?