# Block parameter for Delagator

**URL:** <https://www.ruby-forum.com/t/block-parameter-for-delagator/146864>\
**Category:** Development\
**Created:** [August 26, 2008, 9:38am UTC](https://www.ruby-forum.com/t/block-parameter-for-delagator/146864 "2008-08-26T09:38:57Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [August 26, 2008, 9:38am UTC](https://www.ruby-forum.com/t/block-parameter-for-delagator/146864/1 "2008-08-26T09:38:57Z")

</div>

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 e$B$@$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? e$B8@8l$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?

\_\_  
----------------------------------------------------\>\> e$B@PDMe(B  
e$B7=\<ye(B \<\<—  
----------------------------------\>\> e-mail: removed\_email\_address@domain.invalid \<\<—

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [August 26, 2008, 4:40pm UTC](https://www.ruby-forum.com/t/block-parameter-for-delagator/146864/2 "2008-08-26T16:40:43Z")

</div>

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

2008/08/26 16:33 Keiju ISHITSUKA [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> 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 e$B$@$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? e$B8@8l$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;

@@ -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

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [August 27, 2008, 4:13pm UTC](https://www.ruby-forum.com/t/block-parameter-for-delagator/146864/3 "2008-08-27T16:13:12Z")

</div>

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” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
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)  
{

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

- 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;  
}

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

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [August 27, 2008, 5:59pm UTC](https://www.ruby-forum.com/t/block-parameter-for-delagator/146864/4 "2008-08-27T17:59:59Z")

</div>

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$^$@$^$@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

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%H$KLa$C$?$@$1$@$H8@$&$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$B@PDMe(B  
e$B7=\<ye(B \<\<—  
----------------------------------\>\> e-mail: removed\_email\_address@domain.invalid \<\<—

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [August 27, 2008, 6:19pm UTC](https://www.ruby-forum.com/t/block-parameter-for-delagator/146864/5 "2008-08-27T18:19:20Z")

</div>

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, removed\_email\_address@domain.invalid  
(e$B@PDM7=\<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%H$KLa$C$?$@$1$@$H8@$&$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

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [September 4, 2008, 11:27am UTC](https://www.ruby-forum.com/t/block-parameter-for-delagator/146864/6 "2008-09-04T11:27:59Z")

</div>

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.

\_\_  
----------------------------------------------------\>\> e$B@PDMe(B  
e$B7=\<ye(B \<\<—  
----------------------------------\>\> e-mail: removed\_email\_address@domain.invalid \<\<—
