e$B!!$5$5$@$G$9!%e(B
SASADA Koichi wrote::
e$B!!$H$$$&$3$H$G!$%a%=%C%I$rDj5A$9$kD>A0$K%U%C%/$9$k$?$a$N%a%=%C%I$H$7$Fe(B
Module#method_adding e$B$H$$$&$N$r?7@_$9$k$N$O$I$&$@$m$&!$$H$$$&0F$,$G$^$7e(B
e$B$?!%$9$G$K!$$=$&$$$&$3$H$r$9$kJ}K!$,$"$l$P$$$$$s$G$9$,!$$J$1$l$P!$0l$D8!e(B
e$BF$$48!F$$$$?$@$1$J$$$G$7$g$&$+!%e(B
e$B!!$J$s$H$J$/<BAu$7$F$$^$7$?!%$A$J$$K!$e(Bmethod_added e$B$Ne(B rdoc
e$B$,$J$+$C$?e(B
e$B$N$G!$e(Bsingleton_method_added e$B$r%3%T!<$7$FE,Ev$K=q$-$^$7$?!%e(B
e$B!!5$$E$$$?E@$Oe(B2e$BE@!%e(B
-
…ed e$B7O$N%U%C%/%a%=%C%I$K!$e(B…ing
e$B7O$rIU$12C$($?$/$J$C$F$/$ke(B
e$B7k9=$-$j$,$J$$!%e(Bhook e$B4X?tA4HL$re(B set_trace_func
e$B$_$?$$$K$^$H$a$k!)e(B
-
singleton_*ed e$B$,$"$k%a%=%C%I$Oe(B *ed e$B$Ne(B rdoc e$B$,$J$$!%e(B
Index: object.c
— object.c (e$B%j%S%8%g%se(B 22272)
+++ object.c (e$B:n6H%3%T!<e(B)
@@ -523,6 +523,91 @@ rb_obj_tap(VALUE obj)
*/
/*
-
- Document-method: method_adding
-
-
-
-
-
- Invoked as a callback whenever a method (except singleton method)
-
-
- This method is called before method adding process.
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- */
-
+/*
-
- Document-method: method_added
-
-
-
-
-
- Invoked as a callback whenever a method (except singleton method)
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- */
-
+/*
-
- Document-method: singleton_method_adding
-
-
-
-
-
- Invoked as a callback whenever a singleton method is adding to the
-
- receiver. This method is called before method added process.
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- */
-
+/*
-
-
puts "Adding #{id}"
-
end
-
def self.one() end
-
def two() end
@@ -2488,6 +2573,7 @@ Init_Object(void)
rb_define_method(rb_cBasicObject, “!=”, rb_obj_not_equal, 1);
rb_define_private_method(rb_cBasicObject, "singleton_method_added",
rb_obj_dummy, 1);
- rb_define_private_method(rb_cBasicObject,
“singleton_method_adding”, rb_obj_dummy, 1);
rb_define_private_method(rb_cBasicObject,
“singleton_method_removed”, rb_obj_dummy, 1);
rb_define_private_method(rb_cBasicObject,
“singleton_method_undefined”, rb_obj_dummy, 1);
@@ -2497,6 +2583,7 @@ Init_Object(void)
rb_define_private_method(rb_cModule, “included”, rb_obj_dummy, 1);
rb_define_private_method(rb_cModule, “extended”, rb_obj_dummy, 1);
rb_define_private_method(rb_cModule, “method_added”, rb_obj_dummy,
1);
- rb_define_private_method(rb_cModule, “method_adding”, rb_obj_dummy,
1);
rb_define_private_method(rb_cModule, “method_removed”,
rb_obj_dummy, 1);
rb_define_private_method(rb_cModule, “method_undefined”,
rb_obj_dummy, 1);
Index: vm_method.c
— vm_method.c (e$B%j%S%8%g%se(B 22272)
+++ vm_method.c (e$B:n6H%3%T!<e(B)
@@ -10,7 +10,7 @@ static void rb_vm_check_redefinition_opt
static ID object_id;
static ID removed, singleton_removed, undefined, singleton_undefined;
-static ID added, singleton_added;
+static ID added, singleton_added, adding, singleton_adding;
struct cache_entry { /* method hash table. /
ID mid; / method’s id */
@@ -125,6 +125,17 @@ rb_add_method(VALUE klass, ID mid, NODE
if (OBJ_FROZEN(klass)) {
rb_error_frozen(“class/module”);
}
+
-
if (node && mid != ID_ALLOCATOR && ruby_running) {
-
if (FL_TEST(klass, FL_SINGLETON)) {
-
rb_funcall(rb_iv_get(klass, "__attached__"), singleton_adding, 1,
-
ID2SYM(mid));
-
}
-
else {
-
rb_funcall(klass, adding, 1, ID2SYM(mid));
-
}
-
}
-
rb_clear_cache_by_id(mid);
/*
@@ -749,6 +760,13 @@ rb_alias(VALUE klass, ID name, ID def)
singleton = rb_iv_get(klass, “attached”);
}
-
if (singleton) {
-
rb_funcall(singleton, singleton_adding, 1, ID2SYM(name));
-
}
-
else {
-
rb_funcall(klass, adding, 1, ID2SYM(name));
-
}
-
orig_fbody->nd_cnt++;
if (st_lookup(RCLASS_M_TBL(klass), name, &data)) {
@@ -1132,7 +1150,9 @@ Init_eval_method(void)
object_id = rb_intern(“object_id”);
added = rb_intern(“method_added”);
-
adding = rb_intern(“method_adding”);
singleton_added = rb_intern(“singleton_method_added”);
-
singleton_adding = rb_intern(“singleton_method_adding”);
removed = rb_intern(“method_removed”);
singleton_removed = rb_intern(“singleton_method_removed”);
undefined = rb_intern(“method_undefined”);