diff options
author | shugo <shugo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-12-11 16:48:21 +0000 |
---|---|---|
committer | shugo <shugo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-12-11 16:48:21 +0000 |
commit | b5e9c6cb903aa550713f5f5764964560f98e180f (patch) | |
tree | f73d838c6da7736da75bbd66a26ae12cb61cc631 /test/ruby/test_refinement.rb | |
parent | 9f69bef99bdaf542e3cc93215bcf5e1dbba1b91b (diff) | |
download | ruby-b5e9c6cb903aa550713f5f5764964560f98e180f.tar.gz |
* eval.c (rb_using_refinement): make the method table of an iclass
for a refinement that of the refinement, not that of the origin of
the refinement, which is set by rb_include_class_new(). This
change is needed to make module prepend into a refinement work
properly.
* test/ruby/test_refinement.rb: related test.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38328 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/ruby/test_refinement.rb')
-rw-r--r-- | test/ruby/test_refinement.rb | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/test/ruby/test_refinement.rb b/test/ruby/test_refinement.rb index d572413def..8b4a4fc4e9 100644 --- a/test/ruby/test_refinement.rb +++ b/test/ruby/test_refinement.rb @@ -692,6 +692,69 @@ class TestRefinement < Test::Unit::TestCase IncludeIntoRefinement::User.invoke_baz_on(x)) end + module PrependIntoRefinement + class C + def bar + return "C#bar" + end + + def baz + return "C#baz" + end + end + + module Mixin + def foo + return "Mixin#foo" + end + + def bar + return super << " Mixin#bar" + end + + def baz + return super << " Mixin#baz" + end + end + + module M + refine C do + prepend Mixin + + def baz + return super << " M#baz" + end + end + end + end + + eval <<-EOF, TOPLEVEL_BINDING + using TestRefinement::PrependIntoRefinement::M + + module TestRefinement::PrependIntoRefinement::User + def self.invoke_foo_on(x) + x.foo + end + + def self.invoke_bar_on(x) + x.bar + end + + def self.invoke_baz_on(x) + x.baz + end + end + EOF + + def test_prepend_into_refinement + x = PrependIntoRefinement::C.new + assert_equal("Mixin#foo", PrependIntoRefinement::User.invoke_foo_on(x)) + assert_equal("C#bar Mixin#bar", + PrependIntoRefinement::User.invoke_bar_on(x)) + assert_equal("C#baz M#baz Mixin#baz", + PrependIntoRefinement::User.invoke_baz_on(x)) + end + private def eval_using(mod, s) |