diff options
author | zverok <[email protected]> | 2022-01-25 00:31:12 +0200 |
---|---|---|
committer | Victor Shepelev <[email protected]> | 2022-12-11 18:43:44 +0200 |
commit | f07897fd7bb53a40a8fad5ee2be74e02b53e8614 (patch) | |
tree | 5c2b50f49e17018d28c7744b1419bea0cbe64288 /class.c | |
parent | 73eddee76efdc4ed255fd13533b4a0a329cf3b1a (diff) |
[DOC] Clarify Class#subclases behavior quirks
As per discussion in [Feature #18273], explain the
non-deterministic nature of the method.
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/5480
Diffstat (limited to 'class.c')
-rw-r--r-- | class.c | 21 |
1 files changed, 21 insertions, 0 deletions
@@ -1572,6 +1572,27 @@ class_descendants(VALUE klass, bool immediate_only) * A.subclasses #=> [D, B] * B.subclasses #=> [C] * C.subclasses #=> [] + * + * Anonymous subclasses (not associated with a constant) are + * returned, too: + * + * c = Class.new(A) + * A.subclasses # => [#<Class:0x00007f003c77bd78>, D, B] + * + * Note that the parent does not hold references to subclasses + * and doesn't prevent them from being garbage collected. This + * means that the subclass might disappear when all references + * to it are dropped: + * + * # drop the reference to subclass, it can be garbage-collected now + * c = nil + * + * A.subclasses + * # It can be + * # => [#<Class:0x00007f003c77bd78>, D, B] + * # ...or just + * # => [D, B] + * # ...depending on whether garbage collector was run */ VALUE |