diff options
author | Jeremy Evans <code@jeremyevans.net> | 2021-02-09 15:39:34 -0800 |
---|---|---|
committer | Jeremy Evans <code@jeremyevans.net> | 2021-02-11 07:45:52 -0800 |
commit | 2d877327e12f499ac1a0d7096f4314cc92ef228e (patch) | |
tree | e20d0748b139036111a0d9c0c6f1cbb2606576fd /test/ruby | |
parent | b83ad02997dfa910c08dd2d900f24468c15db264 (diff) | |
download | ruby-2d877327e12f499ac1a0d7096f4314cc92ef228e.tar.gz |
Make a cyclic prepend not modify ancestors for the receiver
Check for cyclic prepend before making any changes. This requires
scanning the module ancestor chain twice, but in general modules
do not have large numbers of ancestors.
Diffstat (limited to 'test/ruby')
-rw-r--r-- | test/ruby/test_module.rb | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/test/ruby/test_module.rb b/test/ruby/test_module.rb index 6b53b7d5f4..0a5597fd6c 100644 --- a/test/ruby/test_module.rb +++ b/test/ruby/test_module.rb @@ -478,6 +478,13 @@ class TestModule < Test::Unit::TestCase assert_raise(ArgumentError) { Module.new { include } } end + def test_prepend_self + m = Module.new + assert_equal([m], m.ancestors) + m.prepend(m) rescue nil + assert_equal([m], m.ancestors) + end + def test_prepend_works_with_duped_classes m = Module.new a = Class.new do |