From 717ab0bb2ee63dfe76076e0c9f91fbac3a0de4fd Mon Sep 17 00:00:00 2001 From: Jeremy Evans Date: Tue, 26 Oct 2021 10:35:21 -0900 Subject: Add Class#descendants Doesn't include receiver or singleton classes. Implements [Feature #14394] Co-authored-by: fatkodima Co-authored-by: Benoit Daloze --- test/ruby/test_class.rb | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'test/ruby') diff --git a/test/ruby/test_class.rb b/test/ruby/test_class.rb index 368c046261..96bca08601 100644 --- a/test/ruby/test_class.rb +++ b/test/ruby/test_class.rb @@ -737,4 +737,22 @@ class TestClass < Test::Unit::TestCase c = Class.new.freeze assert_same(c, Module.new.const_set(:Foo, c)) end + + def test_descendants + c = Class.new + sc = Class.new(c) + ssc = Class.new(sc) + [c, sc, ssc].each do |k| + k.include Module.new + k.new.define_singleton_method(:force_singleton_class){} + end + assert_equal([sc, ssc], c.descendants) + assert_equal([ssc], sc.descendants) + assert_equal([], ssc.descendants) + + object_descendants = Object.descendants + assert_include(object_descendants, c) + assert_include(object_descendants, sc) + assert_include(object_descendants, ssc) + end end -- cgit v1.2.3