diff options
-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) |