1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

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: https://github.com/ruby/ruby/pull/4974
This commit is contained in:
Jean Boussier 2021-10-17 11:40:42 +02:00
parent bd400b479b
commit d8936b755d

View file

@ -18,7 +18,7 @@ class Class
ObjectSpace.each_object(singleton_class).reject do |k|
k.singleton_class? || k == self
end
end
end unless method_defined?(:descendants) # RUBY_VERSION >= "3.1"
# Returns an array with the direct children of +self+.
#