Module#prepend

* class.c (rb_prepend_module): prepend module into another module.
* eval.c (rb_mod_prepend): new method Module#prepend.  [Feature #1102]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36234 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2012-06-27 07:48:50 +00:00
parent 8634544fa7
commit 8ddbbb3324
9 changed files with 148 additions and 2 deletions

View file

@ -1238,4 +1238,36 @@ class TestModule < Test::Unit::TestCase
INPUT
assert_in_out_err([], src, ["NameError"], [])
end
module M0
def m1; [:M0] end
end
module M1
def m1; [:M1, super, :M1] end
end
module M2
def m1; [:M2, super, :M2] end
end
M3 = Module.new do
def m1; [:M3, super, :M3] end
end
module M4
def m1; [:M4, super, :M4] end
end
class C0
include M0
prepend M1
def m1; [:C0, super, :C0] end
end
class C1 < C0
prepend M2, M3
include M4
def m1; [:C1, super, :C1] end
end
def test_prepend
obj = C1.new
expected = [:M2,[:M3,[:C1,[:M4,[:M1,[:C0,[:M0],:C0],:M1],:M4],:C1],:M3],:M2]
assert_equal(expected, obj.m1)
end
end