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

Remove feature checking for Class#descendants

Ref: https://bugs.ruby-lang.org/issues/14394#note-38

Based on Matz's last comment, it's not so clear whether `Class#descendants`
will come back in the same form or at all. So let's not assume anything.
This commit is contained in:
Jean Boussier 2021-12-22 13:45:10 +01:00
parent a8d088fbdc
commit bc07139db3
3 changed files with 23 additions and 35 deletions

View file

@ -3,7 +3,6 @@
require "active_support/ruby_features"
class Class
unless ActiveSupport::RubyFeatures::CLASS_DESCENDANTS
if ActiveSupport::RubyFeatures::CLASS_SUBCLASSES
def descendants
subclasses.concat(subclasses.flat_map(&:descendants))
@ -28,7 +27,6 @@ class Class
end
end
end
end
# Returns an array with the direct children of +self+.
#

View file

@ -51,7 +51,6 @@ module ActiveSupport
unless @clear_disabled
@clear_disabled = true
remove_method(:subclasses)
remove_method(:descendants) if RubyFeatures::CLASS_DESCENDANTS
@@excluded_descendants = nil
end
end
@ -86,17 +85,9 @@ module ActiveSupport
subclasses
end
if RubyFeatures::CLASS_DESCENDANTS
def descendants
descendants = super
descendants.reject! { |d| @@excluded_descendants[d] }
descendants
end
else
def descendants
subclasses.concat(subclasses.flat_map(&:descendants))
end
end
def direct_descendants
ActiveSupport::Deprecation.warn(<<~MSG)

View file

@ -3,6 +3,5 @@
module ActiveSupport
module RubyFeatures # :nodoc:
CLASS_SUBCLASSES = Class.method_defined?(:subclasses) # RUBY_VERSION >= "3.1"
CLASS_DESCENDANTS = Class.method_defined?(:descendants)
end
end