未验证 提交 59a37d5f 编写于 作者: K Kasper Timm Hansen 提交者: GitHub

Merge pull request #37482 from pwim/use-enumerator-in-descendants

Use ObjectSpace.each_object enumerator in descendants
......@@ -15,12 +15,9 @@ class Class
# class D < C; end
# C.descendants # => [B, A, D]
def descendants
descendants = []
ObjectSpace.each_object(singleton_class) do |k|
next if k.singleton_class?
descendants.unshift k unless k == self
ObjectSpace.each_object(singleton_class).reject do |k|
k.singleton_class? || k == self
end
descendants
end
# Returns an array with the direct children of +self+.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册