End of Life Ruby 3.1 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →
instance method · added in Ruby 3.1
Class#subclasses
subclasses → array
object.c
View on GitHub ↗
VALUE
rb_class_subclasses(VALUE klass)
{
return class_descendants(klass, true);
}
Returns an array of classes where the receiver is the direct superclass of the class, excluding singleton classes. The order of the returned array is not defined.
Example
class A; end class B < A; end class C < B; end class D < A; end A.subclasses #=> [D, B] B.subclasses #=> [C] C.subclasses #=> []
Ruby version changes
-
3.1
-
Class#subclasses, which returns an array of classes directly inheriting from the receiver, not including singleton classes. [Feature #18273]Exampleclass A; end class B < A; end class C < B; end class D < A; end A.subclasses #=> [D, B] B.subclasses #=> [C] C.subclasses #=> []
-