mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* 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
This commit is contained in:
parent
9f69bef99b
commit
b5e9c6cb90
3 changed files with 74 additions and 0 deletions
10
ChangeLog
10
ChangeLog
|
@ -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.
|
||||
|
|
1
eval.c
1
eval.c
|
@ -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);
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue