[#92070] [Ruby trunk Feature#15667] Introduce malloc_trim(0) in full gc cycles — sam.saffron@...
Issue #15667 has been updated by sam.saffron (Sam Saffron).
3 messages
2019/04/01
[ruby-core:92355] [Ruby trunk Feature#15781] Unify Method List Introspection?
From:
shevegen@...
Date:
2019-04-21 23:16:44 UTC
List:
ruby-core #92355
Issue #15781 has been updated by shevegen (Robert A. Heiler).
Another idea - partially related perhaps. Or just totally random ...
If we were to ignore the current API, then we could have:
Object#methods
To obtain all methods, as an Array. And then we could still apply filtering
on this result, such as via .public? and .private? and .protected?
Such as:
Object.methods.protected? # return all protected methods
Object.methods.private? # return all private methods
This presently would not work because .methods will return an Array, but
I was thinking of a special Array that could still carry "meta-information"
like this but would behave as Array for all other purposes. (Though it
would be fun to have meta-tags on Arrays ... but I am really just throwing
out random ideas here without having thought about that much at all.)
Alternatively:
Object.protected_methods?
Object.public_methods?
Object.private_methods?
Object.methods?
(The trailing '?' is as an example; it could possibly be omitted. I just
like trailing '?' methods in general, they are really great.)
----------------------------------------
Feature #15781: Unify Method List Introspection?
https://bugs.ruby-lang.org/issues/15781#change-77699
* Author: rbjl (Jan Lelis)
* Status: Open
* Priority: Normal
* Assignee:
* Target version:
----------------------------------------
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](https://idiosyncratic-ruby.com/25-meta-methodology.html)):
- `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](https://github.com/janlelis/object_shadow#method-introspection). 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?
--
https://bugs.ruby-lang.org/
Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>