diff options
author | Jeremy Evans <code@jeremyevans.net> | 2021-10-26 10:35:21 -0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-26 12:35:21 -0700 |
commit | 717ab0bb2ee63dfe76076e0c9f91fbac3a0de4fd (patch) | |
tree | d2b531647657dd58e6ce6e64e3f6fa0adaa75f40 /test/ruby/test_class.rb | |
parent | a4d5ee4f31bf3ff36c1a8c8fe3cda16aa1016b12 (diff) | |
download | ruby-717ab0bb2ee63dfe76076e0c9f91fbac3a0de4fd.tar.gz |
Add Class#descendants
Doesn't include receiver or singleton classes.
Implements [Feature #14394]
Co-authored-by: fatkodima <fatkodima123@gmail.com>
Co-authored-by: Benoit Daloze <eregontp@gmail.com>
Diffstat (limited to 'test/ruby/test_class.rb')
-rw-r--r-- | test/ruby/test_class.rb | 18 |
1 files changed, 18 insertions, 0 deletions
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 |