Project

General

Profile

Actions

Feature #15781

open

Unify Method List Introspection?

Added by rbjl (Jan Lelis) over 2 years ago. Updated over 2 years ago.

Status:
Open
Priority:
Normal
Assignee:
-
Target version:
-
[ruby-core:92353]

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#methods and Module#instance_methods do not include private methods (at the same time they do include protected ones). There is already Object#public_methods (and 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 *_methods methods let's you decide if you want to consider the inheritance chain, or not - But the prominent exception is Object#methods which instead toggles inheritance to singleton only! (for which we also have Object#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

Also available in: Atom PDF