ruby-changes:25561
From: shugo <ko1@a...>
Date: Sun, 11 Nov 2012 13:45:42 +0900 (JST)
Subject: [ruby-changes:25561] shugo:r37618 (trunk): * eval.c (rb_using_refinement, rb_mod_using, f_using): clear method
shugo 2012-11-11 13:45:31 +0900 (Sun, 11 Nov 2012) New Revision: 37618 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=37618 Log: * eval.c (rb_using_refinement, rb_mod_using, f_using): clear method cache only when using is called explicitly. * test/ruby/test_refinement.rb: related test. Modified files: trunk/ChangeLog trunk/eval.c trunk/test/ruby/test_refinement.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 37617) +++ ChangeLog (revision 37618) @@ -1,3 +1,10 @@ +Sun Nov 11 13:41:01 2012 Shugo Maeda <shugo@r...> + + * eval.c (rb_using_refinement, rb_mod_using, f_using): clear method + cache only when using is called explicitly. + + * test/ruby/test_refinement.rb: related test. + Sun Nov 11 12:56:34 2012 Masaki Matsushita <glass.saga@g...> * lib/pstore.rb (PStore): fix not to replace ThreadError raised in Index: eval.c =================================================================== --- eval.c (revision 37617) +++ eval.c (revision 37618) @@ -1087,7 +1087,6 @@ module = RCLASS_SUPER(module); } rb_hash_aset(cref->nd_refinements, klass, iclass); - rb_clear_cache_by_class(klass); } void rb_using_module(NODE *cref, VALUE module); @@ -1153,6 +1152,7 @@ } rb_hash_aset(using_modules, module, Qtrue); rb_using_module(cref, module); + rb_clear_cache(); rb_funcall(module, rb_intern("used"), 1, self); return self; } @@ -1392,6 +1392,7 @@ Check_Type(module, T_MODULE); rb_using_module(cref, module); + rb_clear_cache(); return self; } Index: test/ruby/test_refinement.rb =================================================================== --- test/ruby/test_refinement.rb (revision 37617) +++ test/ruby/test_refinement.rb (revision 37618) @@ -1,4 +1,5 @@ require 'test/unit' +require_relative 'envutil' class TestRefinement < Test::Unit::TestCase class Foo @@ -709,4 +710,72 @@ assert_equal("refined", InlineMethodCache::M.module_eval(&f)) assert_equal("original", f.call) end + + module UsingMethodCache + class C + def foo + "original" + end + end + + module M1 + refine C do + def foo + "M1" + end + end + end + + module M2 + refine C do + def foo + "M2" + end + end + end + + module M + c = C.new + ORIGINAL_FOO = c.foo + using M1 + c.foo + using M2 + M2_FOO = c.foo + end + end + + def test_using_method_cache + assert_equal("original", UsingMethodCache::M::ORIGINAL_FOO) + assert_equal("M2", UsingMethodCache::M::M2_FOO) + + assert_in_out_err([], <<-INPUT, %w(:M1 :M2), []) + class C + def foo + "original" + end + end + + module M1 + refine C do + def foo + :M1 + end + end + end + + module M2 + refine C do + def foo + :M2 + end + end + end + + c = C.new + using M1 + p c.foo + using M2 + p c.foo + INPUT + end end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/