[前][次][番号順一覧][スレッド一覧]

ruby-changes:27182

From: nobu <ko1@a...>
Date: Thu, 14 Feb 2013 10:33:35 +0900 (JST)
Subject: [ruby-changes:27182] nobu:r39234 (trunk): vm_method.c: fix method_removed

nobu	2013-02-14 10:30:47 +0900 (Thu, 14 Feb 2013)

  New Revision: 39234

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=39234

  Log:
    vm_method.c: fix method_removed
    
    * vm_method.c: call method_removed hook on called class, not on
      prepending iclass.

  Modified files:
    trunk/ChangeLog
    trunk/test/ruby/test_module.rb
    trunk/vm_method.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 39233)
+++ ChangeLog	(revision 39234)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Thu Feb 14 10:30:41 2013  Nobuyoshi Nakada  <nobu@r...>
+
+	* vm_method.c: call method_removed hook on called class, not on
+	  prepending iclass.
+
 Thu Feb 14 10:05:57 2013  Eric Hodel  <drbrain@s...>
 
 	* lib/net/http:  Do not handle Content-Encoding when the user sets
Index: vm_method.c
===================================================================
--- vm_method.c	(revision 39233)
+++ vm_method.c	(revision 39234)
@@ -648,6 +648,7 @@ remove_method(VALUE klass, ID mid) https://github.com/ruby/ruby/blob/trunk/vm_method.c#L648
 {
     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) https://github.com/ruby/ruby/blob/trunk/vm_method.c#L675
     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
Index: test/ruby/test_module.rb
===================================================================
--- test/ruby/test_module.rb	(revision 39233)
+++ test/ruby/test_module.rb	(revision 39234)
@@ -1382,12 +1382,27 @@ class TestModule < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_module.rb#L1382
   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

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]