$B$1$$$8$e!w$$$7$D$+$G$9(B.
Ruby1.8 $B$H(B Ruby1.9 $B$H$G$O(B,
$B%V%m%C%/%Q%i%a!<%?EO$7$N?6$kIq$$$N0c$$$G:$$C(B
$B$F$$$k$3$H$,$"$j$^$9(B.
$B0J2<$N%3!<%I$r<B9T$9$k$H(B:
--
require "delegate"
d1 = SimpleDelegator.new([1,2])
d2 = SimpleDelegator.new([3,4])
[d1, d2].each{|a, b| p a, b}
--
Ruby1.8$B$G$O(B, $BG[Ns$NMWAG$,(B, $B3F(Ba, b
$B$KBeF~$5$l$^$9(B.
Ruby1.9 $B$G$O(B, a $B$@$1$K(B d1, d2$BBeF~$5$l(B, b $B$O(B nil
$B$K$J$j$^$9(B.
$B$3$l$C$F(B, 1.9 $B$N;EMM$G$9(B? $B8@8l$N;EMM(B? or Delegator
$B$N;EMM(B?
$B$^$?(B, 1.8
$B$NMM$K?6$kIq$&$h$&$K(BDelegator$B;w$N%/%i%9B&$GBP1~$9$k$3$H$C$F=P(B
$BMh$^$9$G$7$g$&$+(B?
__
---------------------------------------------------->> $B@PDM(B
$B7=<y(B <<---
---------------------------------->> e-mail: keiju@ishitsuka.com <<---
on 26.08.2008 09:38
on 26.08.2008 16:40
$B1sF#$G$9!#(B 2008/08/26 16:33 Keiju ISHITSUKA <keiju@ishitsuka.com>: > Ruby1.8$B$G$O(B, $BG[Ns$NMWAG$,(B, $B3F(Ba, b $B$KBeF~$5$l$^$9(B. > Ruby1.9 $B$G$O(B, a $B$@$1$K(B d1, d2$BBeF~$5$l(B, b $B$O(B nil $B$K$J$j$^$9(B. > > $B$3$l$C$F(B, 1.9 $B$N;EMM$G$9(B? $B8@8l$N;EMM(B? or Delegator $B$N;EMM(B? $B%P%0$+$I$&$+$O$o$+$j$^$;$s$,D>$7$F$_$^$7$?!#(B $B$,!"0J2<$N%3!<%I$,(B 3 $BG\CY$/$J$j$^$7$?!#$I$s$J$b$s$G$7$g$&!#(B $ time ./ruby.org -e '([1] * 5000000).each {|a, b| a }' real 0m1.180s user 0m0.740s sys 0m0.430s $ time ./ruby.new -e '([1] * 5000000).each {|a, b| a }' real 0m3.420s user 0m2.930s sys 0m0.480s $B0l1~%Q%C%A$G$9!#(B Index: vm_insnhelper.c =================================================================== --- vm_insnhelper.c (revision 18871) +++ vm_insnhelper.c (working copy) @@ -704,6 +704,7 @@ int i; int argc = orig_argc; const int m = iseq->argc; + VALUE ary; th->mark_stack_len = argc; @@ -714,8 +715,7 @@ */ if (!(iseq->arg_simple & 0x02) && (m + iseq->arg_post_len) > 0 && - argc == 1 && TYPE(argv[0]) == T_ARRAY) { - VALUE ary = argv[0]; + argc == 1 && !NIL_P(ary = rb_check_array_type(argv[0]))) { th->mark_stack_len = argc = RARRAY_LEN(ary); CHECK_STACK_OVERFLOW(th->cfp, argc); > $B$^$?(B, 1.8 $B$NMM$K?6$kIq$&$h$&$K(BDelegator$B;w$N%/%i%9B&$GBP1~$9$k$3$H$C$F=P(B > $BMh$^$9$G$7$g$&$+(B? $B$?$V$s!"$G$-$J$$$h$&$J5$$,$7$^$9!#(B
on 27.08.2008 16:13
$B$^$D$b$H(B $B$f$-$R$m$G$9(B
In message "Re: [ruby-dev:35988] Re: block parameter for Delagator"
on Tue, 26 Aug 2008 23:34:37 +0900, "Yusuke ENDOH" <mame@tsg.ne.jp>
writes:
|$B%P%0$+$I$&$+$O$o$+$j$^$;$s$,D>$7$F$_$^$7$?!#(B
|$B$,!"0J2<$N%3!<%I$,(B 3 $BG\CY$/$J$j$^$7$?!#$I$s$J$b$s$G$7$g$&!#(B
TYPE(obj) == T_ARRAY$B$H$$$&>r7o$O(Bduck typing$BE*$K$h$/$J$$$H;W(B
$B$&$N$G!"D>$7$?J}$,$h$$$H$O;W$&$N$G$9$,!"3N$+$K@-G=$K$O1F6A$,(B
$B$"$j$^$9$M$(!#(B
$BA}2C$7$?%3%9%H$O<g$K(B
* conver_type$B$KJ8;zNs$GEO$5$l$?%a%=%C%IL>$N(Bintern
* T_ARRAY$B$G$J$+$C$?;~$N(Brespond_to$B$G$N%A%'%C%/(B
$B$J$N$G!"$3$NJU$NL5BL$r:o$C$F$_$^$7$?$,!"$=$l$G$b$^$@$^$@CY$$(B
$B$G$9$M$(!#$^$"!"<B:]$K$O$3$N%3%9%H$,$=$l$[$ILdBj$K$J$k$3$H$O(B
$B$J$$$H$O;W$$$^$9$,!#(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)
{
- ID m;
+ ID m = 0;
+ int i;
- m = rb_intern(method);
+ for (i=0; conv_method_names[i].method; i++) {
+ if (conv_method_names[i].method[0] == method[0] &&
+ strcmp(conv_method_names[i].method, method) == 0) {
+ m = conv_method_names[i].id;
+ break;
+ }
+ }
+ if (!m) m = rb_intern(method);
if (!rb_respond_to(val, m)) {
if (raise) {
rb_raise(rb_eTypeError, "can't convert %s into %s",
@@ -2427,6 +2451,8 @@ boot_defclass(const char *name, VALUE super)
void
Init_Object(void)
{
+ int i;
+
#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];
on 27.08.2008 17:59
$B$1$$$8$e!w$$$7$D$+$G$9(B. $B:G6a(B, Ruby1.8$B$H(BRuby1.9$B$N?6$kIq$$$N0c$$$K$$$m$$$m$HG:$s$G$$$k$b$N$G$9(B. In [ruby-dev :36015 ] the message: "[ruby-dev:36015] Re: block parameter for Delagator ", on Aug/27 23:07(JST) Yukihiro Matsumoto writes: >$B$^$D$b$H(B $B$f$-$R$m$G$9(B >$B$J$N$G!"$3$NJU$NL5BL$r:o$C$F$_$^$7$?$,!"$=$l$G$b$^$@$^$@CY$$(B >$B$G$9$M$(!#$^$"!"<B:]$K$O$3$N%3%9%H$,$=$l$[$ILdBj$K$J$k$3$H$O(B >$B$J$$$H$O;W$$$^$9$,!#(B $BNI$/J,$+$C$F$J$$$G$9$,(B, Ruby1.8$B$G$O$d$C$F$$$?$3$H$J$s$G$9$h$M(B? $B$J$i(B, $B85$N<B9T%3%9%H$KLa$C$?$@$1$@$H8@$&$3$H$G(B. # $B$=$l$H$b(B, $B$3$NJU$j$O(BRuby1.8/1.9$B$G:,K\E*$K0c$&(B? __ ---------------------------------------------------->> $B@PDM(B $B7=<y(B <<--- ---------------------------------->> e-mail: keiju@ishitsuka.com <<---
on 27.08.2008 18:19
$B$^$D$b$H(B $B$f$-$R$m$G$9(B
In message "Re: [ruby-dev:36019] Re: block parameter for Delagator"
on Thu, 28 Aug 2008 00:52:25 +0900, keiju@ishitsuka.com
($B@PDM7=<y(B) writes:
|$B:G6a(B, Ruby1.8$B$H(BRuby1.9$B$N?6$kIq$$$N0c$$$K$$$m$$$m$HG:$s$G$$$k$b$N$G$9(B.
$B$3$3$O0lHV0c$C$F$kItJ,$G$9$+$i$M$(!#(B
|$BNI$/J,$+$C$F$J$$$G$9$,(B, Ruby1.8$B$G$O$d$C$F$$$?$3$H$J$s$G$9$h$M(B? $B$J$i(B,
|$B85$N<B9T%3%9%H$KLa$C$?$@$1$@$H8@$&$3$H$G(B.
|
|# $B$=$l$H$b(B, $B$3$NJU$j$O(BRuby1.8/1.9$B$G:,K\E*$K0c$&(B?
$B40A4$K:F<BAu$5$l$F$$$k$b$N$N!":,K\E*$K0c$&$C$F$3$H$O$J$$$s$G(B
$B$9$,!"A4BN$KB.$/$J$C$F$k$s$G!"CY$/$J$k$HL\N)$D$s$G$9$h$M!#(B
on 04.09.2008 11:27
$B$1$$$8$e!w$$$7$D$+$G$9(B. In [ruby-dev :36022 ] the message: "[ruby-dev:36022] Re: block parameter for Delagator ", on Aug/28 01:13(JST) Yukihiro Matsumoto writes: >$B$^$D$b$H(B $B$f$-$R$m$G$9(B >|$B:G6a(B, Ruby1.8$B$H(BRuby1.9$B$N?6$kIq$$$N0c$$$K$$$m$$$m$HG:$s$G$$$k$b$N$G$9(B. >$B$3$3$O0lHV0c$C$F$kItJ,$G$9$+$i$M$(!#(B $B$G$9$M$'(B.... >$B40A4$K:F<BAu$5$l$F$$$k$b$N$N!":,K\E*$K0c$&$C$F$3$H$O$J$$$s$G(B >$B$9$,!"A4BN$KB.$/$J$C$F$k$s$G!"CY$/$J$k$HL\N)$D$s$G$9$h$M!#(B respond_to?$B$,F~$C$F$$$k$H$$$&$3$H$O(B, 1$B%a%=%C%I<B9TJ,$0$i$$%3%9%H$,A}$((B $B$F$$$k$C$F$3$H$G$7$g$&$M(B? trunk$B$K%A%'%C%/%$%s$5$l$?$_$?$$$G$9$M(B. $B5$;}NI$/F0$/MM$K$J$j$^$7$?(B. __ ---------------------------------------------------->> $B@PDM(B $B7=<y(B <<--- ---------------------------------->> e-mail: keiju@ishitsuka.com <<---