mirror of
https://github.com/ruby/ruby.git
synced 2025-09-23 20:44:00 +02:00
prepend: fix ancestors order
* class.c (rb_mod_ancestors): fix ancestors order. [ruby-core:45919][Bug #6658] [ruby-dev:45861][Bug #6659] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36241 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
c686986220
commit
3f3225905b
3 changed files with 49 additions and 5 deletions
|
@ -1273,9 +1273,9 @@ class TestModule < Test::Unit::TestCase
|
|||
|
||||
def test_prepend_inheritance
|
||||
bug6654 = '[ruby-core:45914]'
|
||||
a = Module.new
|
||||
b = Module.new {include a}
|
||||
c = Class.new {prepend b}
|
||||
a = labeled_module("a")
|
||||
b = labeled_module("b") {include a}
|
||||
c = labeled_class("c") {prepend b}
|
||||
assert_operator(c, :<, b, bug6654)
|
||||
assert_operator(c, :<, a, bug6654)
|
||||
end
|
||||
|
@ -1299,4 +1299,32 @@ class TestModule < Test::Unit::TestCase
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
def test_prepend_class_ancestors
|
||||
bug6658 = '[ruby-core:45919]'
|
||||
m = labeled_module("m")
|
||||
c = labeled_class("c") {prepend m}
|
||||
assert_equal([m, c], c.ancestors[0, 2], bug6658)
|
||||
end
|
||||
|
||||
def test_prepend_module_ancestors
|
||||
bug6659 = '[ruby-dev:45861]'
|
||||
m0 = labeled_module("m0")
|
||||
m1 = labeled_module("m1") {prepend m0}
|
||||
assert_equal([m0, m1], m1.ancestors, bug6659)
|
||||
end
|
||||
|
||||
def labeled_module(name, &block)
|
||||
Module.new do
|
||||
singleton_class.class_eval {define_method(:to_s) {name}}
|
||||
class_eval(&block) if block
|
||||
end
|
||||
end
|
||||
|
||||
def labeled_class(name, superclass = Object, &block)
|
||||
Class.new(superclass) do
|
||||
singleton_class.class_eval {define_method(:to_s) {name}}
|
||||
class_eval(&block) if block
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue