1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* eval.c (rb_overlay_module, rb_mod_refine): accept a module as the

argument of Module#refine.

* vm_method.c (search_method): if klass is an iclass, lookup the
  original module of the iclass in omod in order to allow
  refinements of modules.

* test/ruby/test_refinement.rb: add tests for the above changes.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37040 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
shugo 2012-09-27 09:53:24 +00:00
parent e0bff65092
commit 8940e37210
4 changed files with 94 additions and 7 deletions

View file

@ -324,5 +324,61 @@ class TestRefinement < Test::Unit::TestCase
obj = c.new
assert_equal([:c, :m1, :m2], m2.module_eval { obj.foo })
end
end
def test_refine_module_without_overriding
m1 = Module.new
c = Class.new {
include m1
}
m2 = Module.new {
refine m1 do
def foo
:m2
end
end
}
obj = c.new
assert_equal(:m2, m2.module_eval { obj.foo })
end
def test_refine_module_with_overriding
m1 = Module.new {
def foo
[:m1]
end
}
c = Class.new {
include m1
}
m2 = Module.new {
refine m1 do
def foo
super << :m2
end
end
}
obj = c.new
assert_equal([:m1, :m2], m2.module_eval { obj.foo })
end
def test_refine_neither_class_nor_module
assert_raise(TypeError) do
Module.new {
refine Object.new do
end
}
end
assert_raise(TypeError) do
Module.new {
refine 123 do
end
}
end
assert_raise(TypeError) do
Module.new {
refine "foo" do
end
}
end
end
end