Actions
Feature #15781
openUnify Method List Introspection?
Feature #15781:
Unify Method List Introspection?
Status:
Open
Assignee:
-
Target version:
-
Description
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):
-
Object#methodsandModule#instance_methodsdo not include private methods (at the same time they do include protected ones). There is alreadyObject#public_methods(andObject#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 isObject#methodswhich instead toggles inheritance to singleton only! (for which we also haveObject#singleton_methods) - 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
BasicObject)?
What do you think about having one unified way for retrieving an object's method list?
Actions