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

Merge pull request #39505 from jonathanhefner/alias-subclasses-as-direct_descendants

Alias direct_descendants as subclasses
This commit is contained in:
Eugene Kenny 2020-06-03 10:26:34 +01:00 committed by GitHub
commit b93608c059
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 0 deletions

View file

@ -13,6 +13,7 @@ module ActiveSupport
descendants = @@direct_descendants[klass] descendants = @@direct_descendants[klass]
descendants ? descendants.to_a : [] descendants ? descendants.to_a : []
end end
alias_method :subclasses, :direct_descendants
def descendants(klass) def descendants(klass)
arr = [] arr = []
@ -59,6 +60,7 @@ module ActiveSupport
def direct_descendants def direct_descendants
DescendantsTracker.direct_descendants(self) DescendantsTracker.direct_descendants(self)
end end
alias_method :subclasses, :direct_descendants
def descendants def descendants
DescendantsTracker.descendants(self) DescendantsTracker.descendants(self)

View file

@ -42,6 +42,12 @@ module DescendantsTrackerTestCases
assert_equal_sets [], Child2.direct_descendants assert_equal_sets [], Child2.direct_descendants
end end
def test_subclasses
[Parent, Child1, Child2].each do |klass|
assert_equal klass.direct_descendants, klass.subclasses
end
end
def test_clear def test_clear
mark_as_autoloaded(*ALL) do mark_as_autoloaded(*ALL) do
ActiveSupport::DescendantsTracker.clear ActiveSupport::DescendantsTracker.clear