Skip to content

Commit d8936b7

Browse files
committed
Use the native Class#descendants if available
Ruby 3.1 is very likely to ship with a native implementation of `Class#descendants` that doesn't need to iterate over ObjectSpace. So we should use it if available. Ref: https://bugs.ruby-lang.org/issues/14394 Ref: ruby/ruby#4974
1 parent bd400b4 commit d8936b7

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

activesupport/lib/active_support/core_ext/class/subclasses.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def descendants
1818
ObjectSpace.each_object(singleton_class).reject do |k|
1919
k.singleton_class? || k == self
2020
end
21-
end
21+
end unless method_defined?(:descendants) # RUBY_VERSION >= "3.1"
2222

2323
# Returns an array with the direct children of +self+.
2424
#

0 commit comments

Comments
 (0)