[DOC] Clarify Class#subclases behavior quirks
As per discussion in [Feature #18273], explain the non-deterministic nature of the method.
This commit is contained in:
parent
73eddee76e
commit
f07897fd7b
Notes:
git
2022-12-11 16:44:07 +00:00
21
class.c
21
class.c
@ -1572,6 +1572,27 @@ class_descendants(VALUE klass, bool immediate_only)
|
|||||||
* A.subclasses #=> [D, B]
|
* A.subclasses #=> [D, B]
|
||||||
* B.subclasses #=> [C]
|
* B.subclasses #=> [C]
|
||||||
* C.subclasses #=> []
|
* 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
|
VALUE
|
||||||
|
Loading…
x
Reference in New Issue
Block a user