提交 8065b453 编写于 作者: V Vipul A M 提交者: GitHub

Merge pull request #26392 from y-yagi/chage_descendants_to_public_api

change `Class#descendants` to public API [ci skip]
......@@ -6,7 +6,20 @@ class Class
# Test if this Ruby supports each_object against singleton_class
ObjectSpace.each_object(Numeric.singleton_class) {}
def descendants # :nodoc:
# Returns an array with all classes that are < than its receiver.
#
# class C; end
# C.descendants # => []
#
# class B < C; end
# C.descendants # => [B]
#
# class A < B; end
# C.descendants # => [B, A]
#
# class D < C; end
# C.descendants # => [B, A, D]
def descendants
descendants = []
ObjectSpace.each_object(singleton_class) do |k|
descendants.unshift k unless k == self
......@@ -14,7 +27,7 @@ def descendants # :nodoc:
descendants
end
rescue StandardError # JRuby 9.0.4.0 and earlier
def descendants # :nodoc:
def descendants
descendants = []
ObjectSpace.each_object(Class) do |k|
descendants.unshift k if k < self
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册