Skip to content

Commit

Permalink
Exclude singleton classes from subclasses and descendants
Browse files Browse the repository at this point in the history
This behavior changed in Ruby starting with 2.3.0, as a result of
https://bugs.ruby-lang.org/issues/11360. This results in a change in
behavior of these methods which is likely undesirable.

Fixes #27238
  • Loading branch information
sgrif committed Dec 1, 2016
1 parent 2204233 commit 4e73ffa
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
Expand Up @@ -22,6 +22,7 @@ class Class
def descendants
descendants = []
ObjectSpace.each_object(singleton_class) do |k|
next if k.singleton_class?
descendants.unshift k unless k == self
end
descendants
Expand Down
10 changes: 10 additions & 0 deletions activesupport/test/core_ext/class_test.rb
Expand Up @@ -25,4 +25,14 @@ def test_subclasses
assert_equal [Baz], Bar.subclasses
assert_equal [], Baz.subclasses
end

def test_descendants_excludes_singleton_classes
klass = Parent.new.singleton_class
refute Parent.descendants.include?(klass), "descendants should not include singleton classes"
end

def test_subclasses_excludes_singleton_classes
klass = Parent.new.singleton_class
refute Parent.subclasses.include?(klass), "subclasses should not include singleton classes"
end
end

0 comments on commit 4e73ffa

Please sign in to comment.