# Block parameter for Delagator

e\$B\$1\$\$\$8\$e!w\$\$\$7\$D\$+\$G\$9e(B.

Ruby1.8 e\$B\$He(B Ruby1.9 e\$B\$H\$G\$Oe(B,
e\$B%V%m%C%/%Q%i%a!<%?EO\$7\$N?6\$kIq\$\$\$N0c\$\$\$G:\$\$Ce(B
e\$B\$F\$\$\$k\$3\$H\$,\$"\$j\$^\$9e(B.

e\$B0J2<\$N%3!<%I\$r<B9T\$9\$k\$He(B:

require “delegate”

d1 = SimpleDelegator.new([1,2])
d2 = SimpleDelegator.new([3,4])

## [d1, d2].each{|a, b| p a, b}

Ruby1.8e\$B\$G\$Oe(B, e\$BG[Ns\$NMWAG\$,e(B, e\$B3Fe(Ba, b
e\$B\$KBeF~\$5\$l\$^\$9e(B.
Ruby1.9 e\$B\$G\$Oe(B, a [email protected]\$1\$Ke(B d1, d2e\$BBeF~\$5\$le(B, b e\$B\$Oe(B nil
e\$B\$K\$J\$j\$^\$9e(B.

e\$B\$3\$l\$C\$Fe(B, 1.9 e\$B\$N;EMM\$G\$9e(B? [email protected]\$N;EMMe(B? or Delegator
e\$B\$N;EMMe(B?

e\$B\$^\$?e(B, 1.8
e\$B\$NMM\$K?6\$kIq\$&\$h\$&\$Ke(BDelegatore\$B;w\$N%/%i%9B&\$GBP1~\$9\$k\$3\$H\$C\$F=Pe(B
e\$BMh\$^\$9\$G\$7\$g\$&\$+e(B?

__
---------------------------------------------------->> [email protected](B
e\$B7=<ye(B <<—
---------------------------------->> e-mail: [email protected] <<—

e\$B1sF#\$G\$9!#e(B

2008/08/26 16:33 Keiju ISHITSUKA [email protected]:

Ruby1.8e\$B\$G\$Oe(B, e\$BG[Ns\$NMWAG\$,e(B, e\$B3Fe(Ba, b e\$B\$KBeF~\$5\$l\$^\$9e(B.
Ruby1.9 e\$B\$G\$Oe(B, a [email protected]\$1\$Ke(B d1, d2e\$BBeF~\$5\$le(B, b e\$B\$Oe(B nil e\$B\$K\$J\$j\$^\$9e(B.

e\$B\$3\$l\$C\$Fe(B, 1.9 e\$B\$N;EMM\$G\$9e(B? [email protected]\$N;EMMe(B? or Delegator e\$B\$N;EMMe(B?

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

\$ 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

e\$B0l1~%Q%C%A\$G\$9!#e(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);
``````

e\$B\$^\$?e(B, 1.8 e\$B\$NMM\$K?6\$kIq\$&\$h\$&\$Ke(BDelegatore\$B;w\$N%/%i%9B&\$GBP1~\$9\$k\$3\$H\$C\$F=Pe(B
e\$BMh\$^\$9\$G\$7\$g\$&\$+e(B?

e\$B\$?\$V\$s!"\$G\$-\$J\$\$\$h\$&\$J5\$\$,\$7\$^\$9!#e(B

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\$,!“[email protected]=\$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\$^[email protected]\$^[email protected]\$\$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)
{

• 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];

e\$B\$1\$\$\$8\$e!w\$\$\$7\$D\$+\$G\$9e(B.

e\$B:G6ae(B,
Ruby1.8e\$B\$He(BRuby1.9e\$B\$N?6\$kIq\$\$\$N0c\$\$\$K\$\$\$m\$\$\$m\$HG:\$s\$G\$\$\$k\$b\$N\$G\$9e(B.

In [ruby-dev :36015 ] the message: "[ruby-dev:36015] Re: block
parameter for Delagator ", on Aug/27 23:07(JST) Yukihiro M.
writes:

e\$B\$^\$D\$b\$He(B e\$B\$f\$-\$R\$m\$G\$9e(B

e\$B\$J\$N\$G!"\$3\$NJU\$NL5BL\$r:o\$C\$F\$_\$^\$7\$?\$,!"\$=\$l\$G\$b\$^[email protected]\$^[email protected]\$\$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

e\$BNI\$/J,\$+\$C\$F\$J\$\$\$G\$9\$,e(B,
Ruby1.8e\$B\$G\$O\$d\$C\$F\$\$\$?\$3\$H\$J\$s\$G\$9\$h\$Me(B? e\$B\$J\$ie(B,
e\$B85\$N<B9T%3%9%[email protected][email protected][email protected]\$&\$3\$H\$Ge(B.

# e\$B\$=\$l\$H\$be(B, e\$B\$3\$NJU\$j\$Oe(BRuby1.8/1.9e\$B\$G:,K\E*\$K0c\$&e(B?

__
---------------------------------------------------->> [email protected](B
e\$B7=<ye(B <<—
---------------------------------->> e-mail: [email protected] <<—

e\$B\$^\$D\$b\$He(B e\$B\$f\$-\$R\$m\$G\$9e(B

In message “Re: [ruby-dev:36019] Re: block parameter for Delagator”
on Thu, 28 Aug 2008 00:52:25 +0900, [email protected]
([email protected]=<ye(B) writes:

|e\$B:G6ae(B, Ruby1.8e\$B\$He(BRuby1.9e\$B\$N?6\$kIq\$\$\$N0c\$\$\$K\$\$\$m\$\$\$m\$HG:\$s\$G\$\$\$k\$b\$N\$G\$9e(B.

e\$B\$3\$3\$O0lHV0c\$C\$F\$kItJ,\$G\$9\$+\$i\$M\$(!#e(B

|e\$BNI\$/J,\$+\$C\$F\$J\$\$\$G\$9\$,e(B, Ruby1.8e\$B\$G\$O\$d\$C\$F\$\$\$?\$3\$H\$J\$s\$G\$9\$h\$Me(B? e\$B\$J\$ie(B,
|e\$B85\$N<B9T%3%9%[email protected][email protected][email protected]\$&\$3\$H\$Ge(B.
|
|# e\$B\$=\$l\$H\$be(B, e\$B\$3\$NJU\$j\$Oe(BRuby1.8/1.9e\$B\$G:,K\E*\$K0c\$&e(B?

e\$B40A4\$K:F<BAu\$5\$l\$F\$\$\$k\$b\$N\$N!":,K\E*\$K0c\$&\$C\$F\$3\$H\$O\$J\$\$\$s\$Ge(B
e\$B\$9\$,!"A4BN\$KB.\$/\$J\$C\$F\$k\$s\$G!"CY\$/\$J\$k\$HL\N)\$D\$s\$G\$9\$h\$M!#e(B

e\$B\$1\$\$\$8\$e!w\$\$\$7\$D\$+\$G\$9e(B.

In [ruby-dev :36022 ] the message: "[ruby-dev:36022] Re: block
parameter for Delagator ", on Aug/28 01:13(JST) Yukihiro M.
writes:

e\$B\$^\$D\$b\$He(B e\$B\$f\$-\$R\$m\$G\$9e(B

|e\$B:G6ae(B, Ruby1.8e\$B\$He(BRuby1.9e\$B\$N?6\$kIq\$\$\$N0c\$\$\$K\$\$\$m\$\$\$m\$HG:\$s\$G\$\$\$k\$b\$N\$G\$9e(B.
e\$B\$3\$3\$O0lHV0c\$C\$F\$kItJ,\$G\$9\$+\$i\$M\$(!#e(B

e\$B\$G\$9\$M\$'e(B…

e\$B40A4\$K:F<BAu\$5\$l\$F\$\$\$k\$b\$N\$N!":,K\E*\$K0c\$&\$C\$F\$3\$H\$O\$J\$\$\$s\$Ge(B
e\$B\$9\$,!"A4BN\$KB.\$/\$J\$C\$F\$k\$s\$G!"CY\$/\$J\$k\$HL\N)\$D\$s\$G\$9\$h\$M!#e(B

respond_to?e\$B\$,F~\$C\$F\$\$\$k\$H\$\$\$&\$3\$H\$Oe(B,
1e\$B%a%=%C%I<B9TJ,\$0\$i\$\$%3%9%H\$,A}\$(e(B
e\$B\$F\$\$\$k\$C\$F\$3\$H\$G\$7\$g\$&\$Me(B?

trunke\$B\$K%A%’%C%/%\$%s\$5\$l\$?\$_\$?\$\$\$G\$9\$Me(B.
e\$B5\$;}NI\$/F0\$/MM\$K\$J\$j\$^\$7\$?e(B.

__
---------------------------------------------------->> [email protected](B
e\$B7=<ye(B <<—
---------------------------------->> e-mail: [email protected] <<—