e$B$^$D$b$He(B e$B$f$-$R$m$G$9e(B
In message “Re: [ruby-dev:35988] Re: block parameter for Delagator”
on Tue, 26 Aug 2008 23:34:37 +0900, “Yusuke ENDOH” [email protected]
writes:
|e$B%P%0$+$I$&$+$O$o$+$j$^$;$s$,D>$7$F$_$^$7$?!#e(B
|e$B$,!"0J2<$N%3!<%I$,e(B 3 e$BG\CY$/$J$j$^$7$?!#$I$s$J$b$s$G$7$g$&!#e(B
TYPE(obj) == T_ARRAYe$B$H$$$&>r7o$Oe(Bduck typinge$BE*$K$h$/$J$$$H;We(B
e$B$&$N$G!"D>$7$?J}$,$h$$$H$O;W$&$N$G$9$,!“3N$+$K@-G=$K$O1F6A$,e(B
e$B$”$j$^$9$M$(!#e(B
e$BA}2C$7$?%3%9%H$O<g$Ke(B
- conver_typee$B$KJ8;zNs$GEO$5$l$?%a%=%C%IL>$Ne(Bintern
- T_ARRAYe$B$G$J$+$C$?;~$Ne(Brespond_toe$B$G$N%A%'%C%/e(B
e$B$J$N$G!“$3$NJU$NL5BL$r:o$C$F$_$^$7$?$,!”$=$l$G$b$^$@$^$@CY$$e(B
e$B$G$9$M$(!#$^$“!”<B:]$K$O$3$N%3%9%H$,$=$l$[$ILdBj$K$J$k$3$H$Oe(B
e$B$J$$$H$O;W$$$^$9$,!#e(B
diff --git a/object.c b/object.c
index fd15e87…dd71c1b 100644
— a/object.c
+++ b/object.c
@@ -1960,12 +1960,36 @@ rb_mod_cvar_defined(VALUE obj, VALUE iv)
return rb_cvar_defined(obj, id);
}
+static struct conv_method_tbl {
- const char *method;
- ID id;
+} conv_method_names[] = {
- {“to_int”, 0},
- {“to_ary”, 0},
- {“to_str”, 0},
- {“to_sym”, 0},
- {“to_hash”, 0},
- {“to_proc”, 0},
- {“to_io”, 0},
- {“to_a”, 0},
- {“to_s”, 0},
- {NULL, 0}
+};
-
static VALUE
convert_type(VALUE val, const char *tname, const char *method, int
raise)
{
#undef rb_intern
#define rb_intern(str) rb_intern_const(str)
@@ -2606,4 +2632,8 @@ Init_Object(void)
id_match = rb_intern(“=~”);
id_inspect = rb_intern(“inspect”);
id_init_copy = rb_intern(“initialize_copy”);
+
-
for (i=0; conv_method_names[i].method; i++) {
-
conv_method_names[i].id = rb_intern(conv_method_names[i].method);
-
}
}
diff --git a/vm_method.c b/vm_method.c
index 0254741…82ae5a4 100644
— a/vm_method.c
+++ b/vm_method.c
@@ -292,8 +292,9 @@ rb_method_node(VALUE klass, ID id)
struct cache_entry *ent;
ent = cache + EXPR1(klass, id);
- if (ent->mid == id && ent->klass == klass && ent->method) {
- return ent->method;
-
if (ent->mid == id && ent->klass == klass) {
-
if (ent->method) return ent->method;
-
return 0;
}
return rb_get_method_body(klass, id, 0);
@@ -1067,9 +1068,13 @@ int
rb_obj_respond_to(VALUE obj, ID id, int priv)
{
VALUE klass = CLASS_OF(obj);
-
NODE * node = rb_method_node(klass, id);
- if (rb_method_basic_definition_p(klass, idRespond_to)) {
- return rb_method_boundp(klass, id, !priv);
- if (node && (node->nd_noex & NOEX_BASIC)) {
- if (!priv && (node->nd_noex & NOEX_PRIVATE)) {
-
return Qtrue;
- }
- return Qfalse;
}
else {
VALUE args[2];