From 01e43fb0e23c2c0c89454945a71db733fbf77409 Mon Sep 17 00:00:00 2001 From: nobu Date: Thu, 14 Feb 2013 01:30:47 +0000 Subject: [PATCH] vm_method.c: fix method_removed * vm_method.c: call method_removed hook on called class, not on prepending iclass. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@39234 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 5 +++++ test/ruby/test_module.rb | 19 +++++++++++++++++-- vm_method.c | 3 ++- 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index f948041925..2effc452a1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Thu Feb 14 10:30:41 2013 Nobuyoshi Nakada + + * vm_method.c: call method_removed hook on called class, not on + prepending iclass. + Thu Feb 14 10:05:57 2013 Eric Hodel * lib/net/http: Do not handle Content-Encoding when the user sets diff --git a/test/ruby/test_module.rb b/test/ruby/test_module.rb index 6e25dac1d5..7723bc16be 100644 --- a/test/ruby/test_module.rb +++ b/test/ruby/test_module.rb @@ -1382,12 +1382,27 @@ class TestModule < Test::Unit::TestCase end def test_prepend_remove_method + c = Class.new do + prepend Module.new {def foo; end} + end assert_raise(NameError) do - Class.new do - prepend Module.new {def foo; end} + c.class_eval do remove_method(:foo) end end + c.class_eval do + def foo; end + end + removed = nil + c.singleton_class.class_eval do + define_method(:method_removed) {|id| removed = id} + end + assert_nothing_raised(NoMethodError, NameError) do + c.class_eval do + remove_method(:foo) + end + end + assert_equal(:foo, removed) end def test_prepend_class_ancestors diff --git a/vm_method.c b/vm_method.c index a82ba5faea..1dbbdd511b 100644 --- a/vm_method.c +++ b/vm_method.c @@ -648,6 +648,7 @@ remove_method(VALUE klass, ID mid) { st_data_t key, data; rb_method_entry_t *me = 0; + VALUE self = klass; klass = RCLASS_ORIGIN(klass); if (klass == rb_cObject) { @@ -674,7 +675,7 @@ remove_method(VALUE klass, ID mid) rb_clear_cache_for_undef(klass, mid); rb_unlink_method_entry(me); - CALL_METHOD_HOOK(klass, removed, mid); + CALL_METHOD_HOOK(self, removed, mid); } void