mirror of
https://github.com/ruby/ruby.git
synced 2025-09-23 20:44:00 +02:00
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.
This commit is contained in:
parent
b83ad02997
commit
2d877327e1
Notes:
git
2021-02-12 00:46:21 +09:00
2 changed files with 19 additions and 2 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue