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 | |
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
-rw-r--r-- | ChangeLog | 10 | ||||
-rw-r--r-- | eval.c | 1 | ||||
-rw-r--r-- | test/ruby/test_refinement.rb | 63 |
3 files changed, 74 insertions, 0 deletions
@@ -1,3 +1,13 @@ +Wed Dec 12 01:47:02 2012 Shugo Maeda <shugo@ruby-lang.org> + + * 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. + Wed Dec 12 01:05:04 2012 NARUSE, Yui <naruse@ruby-lang.org> * tool/make-snapshot: add --disable-rubygem to both MINIRUBY and RUBY. @@ -1078,6 +1078,7 @@ rb_using_refinement(NODE *cref, VALUE klass, VALUE module) FL_SET(module, RMODULE_IS_OVERLAID); c = iclass = rb_include_class_new(module, superclass); RCLASS_REFINED_CLASS(c) = klass; + RCLASS_M_TBL(c) = RCLASS_M_TBL(module); module = RCLASS_SUPER(module); while (module && module != klass) { FL_SET(module, RMODULE_IS_OVERLAID); 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) |