Enumerable#each_* and Enumerable#enum_* on 1.9

e$B$3$s$K$A$O!"$J$+$`$ie(B(e$B$&e(B)e$B$G$9!#e(B

e$B$A$g$C$He(B1.9e$B$Ne(BEnumerablee$B$GM7$s$G$$$F5$IU$$$?$N$G$9$,!"e(B1.9e$B$G$Oe(B
e$B%V%m%C%/$rH<$o$J$$%$%F%l!<%?8F$S=P$7%a%=%C%I8F$S=P$7e(B([email protected]$Ce(B
e$B$F$k$N$+$o$+$s$J$$e(B)e$B$Oe(BEnumerable::Enumeratore$B%*%V%8%’%/%H$rJV$9e(B
e$B$N$K!“85!9e(Benumerator.soe$B$K$”$C$?%$%F%l!<%?8F$S=P$7%a%=%C%I$O$=e(B
e$B$&$J$C$F$$$^$;$s!#e(B

e$B$3$l$O!"$=$l$>$l$N%$%F%l!<%?8F$S=P$7%a%=%C%I$KBP1~$7$?e(Benum_e$B$Je(B
e$B$s$H$+%a%=%C%I$,[email protected]$H;W$$$^$9$,!"$3$l$OD>46e(B
e$B$KH?$9$k5$$,$9$k$N$G!"e(B

(1) e$B3F%$%F%l!<%?8F$S=P$7%a%=%C%I$,%V%m%C%/$J$7$G8F$S=P$5$l$?e(B
e$B>l9g$Oe(BEnumerable::Enumeratore$B%*%V%8%’%/%H$rJV$9$h$&$K$7!"e(B
(2)
e$B$=$l$i$KBP1~$7$F$$$?e(Benum_*e$B%a%=%C%I$OGQ;$9$ke(B(e$B$^$?$O!"e(B1.9
e$B$G$OGQ;
$7$J$$$^$G$b7Y9p$9$ke(B)

e$B$H$$$&$N$O$I$&$G$7$g$&$+e(B?

e$B$=$l$G$O!#e(B

[email protected]$G$9!#e(B

At Wed, 9 Aug 2006 23:07:12 +0900,
U.Nakamura wrote in [ruby-dev:29246]:

(1) e$B3F%$%F%l!<%?8F$S=P$7%a%=%C%I$,%V%m%C%/$J$7$G8F$S=P$5$l$?e(B
e$B>l9g$Oe(BEnumerable::Enumeratore$B%*%V%8%’%/%H$rJV$9$h$&$K$7!"e(B

e$B$3$l$O$$$$$s$G$9$,e(B

(2) e$B$=$l$i$KBP1~$7$F$$$?e(Benum_*e$B%a%=%C%I$OGQ;$9$ke(B(e$B$^$?$O!"e(B1.9
e$B$G$OGQ;
$7$J$$$^$G$b7Y9p$9$ke(B)

e$BJL$K$=$N$^$^;D$7$F$*$$$F$b$$$$$s$8$c$J$$$G$7$g$&$+!#e(B

e$B$D$$$G$K!"e(BEnumerator#enum_ife$B$He(BEnumerable#calle$B$H$$$&$N$bDs0F$7$Fe(B
e$B$_$^$9!#e(B

Index: enumerator.c

RCS file: /cvs/ruby/src/ruby/enumerator.c,v
retrieving revision 1.13
diff -p -U 2 -r1.13 enumerator.c
— enumerator.c 9 Jun 2006 21:20:13 -0000 1.13
+++ enumerator.c 9 Aug 2006 16:09:47 -0000
@@ -154,4 +154,6 @@ enum_each_slice(VALUE obj, VALUE n)
if (size <= 0) rb_raise(rb_eArgError, “invalid slice size”);

  • RETURN_ENUMERATOR(obj, 1, (n = LONG2NUM(size), &n));

  • args[0] = rb_ary_new2(size);
    args[1] = (VALUE)size;
    @@ -221,4 +223,7 @@ enum_each_cons(VALUE obj, VALUE n)

    if (size <= 0) rb_raise(rb_eArgError, “invalid size”);

  • RETURN_ENUMERATOR(obj, 1, (n = LONG2NUM(size), &n));

  • args[0] = rb_ary_new2(size);
    args[1] = (VALUE)size;
    @@ -352,4 +357,6 @@ enumerator_with_index(VALUE obj)
    VALUE *argv = 0;

  • RETURN_ENUMERATOR(obj, 0, 0);

  • if (e->args) {
    argc = RARRAY(e->args)->len;
    @@ -360,4 +367,56 @@ enumerator_with_index(VALUE obj)
    }

+static VALUE
+enumerator_select(VALUE i, struct enumerator *e)
+{

  • if (!RTEST(proc_call(e->proc, i))) return Qnil;
  • return rb_yield(i);
    +}

+/*

    • call-seq:
    • e.enum_if {…}
    • Returns an Enumerator which yields when the condition proc
    • returns true value.
    • e.g.:
    •  (1..10).enum_if {|i| (i%3).zero?}.each {|a| p a}
      
    •  # outputs below
      
    •  3
      
    •  6
      
    •  9
      
  • */
    +static VALUE
    +enumerator_enum_if(argc, argv, obj)
  • int argc;
  • VALUE *argv;
  • VALUE obj;
    +{
  • struct enumerator *ptr;
  • obj = obj_to_enum(argc, argv, obj);
  • ptr = DATA_PTR(obj);
  • if (ptr->iter == enumerator_iter_i) ptr->iter = enumerator_select;
  • return obj;
    +}

+/*

    • call-seq:
    • enum.call(…)
    • Calls the bound method specified in the first place with addition
    • arguments.
  • */
    +static VALUE
    +enumerator_call(obj, args)
  • VALUE obj, args;
    +{
  • struct enumerator *e = enumerator_ptr(obj);
  • args = rb_ary_concat(e->args, args);
  • return rb_method_call(RARRAY(args)->len, RARRAY(args)->ptr,
    e->method);
    +}

void
Init_Enumerator(void)
@@ -371,4 +430,5 @@ Init_Enumerator(void)
rb_define_method(rb_mEnumerable, “each_cons”, enum_each_cons, 1);
rb_define_method(rb_mEnumerable, “enum_cons”, enumerator_enum_cons,
1);

  • rb_define_method(rb_mEnumerable, “enum_if”, enumerator_enum_if,
    -1);

    rb_cEnumerator = rb_define_class_under(rb_mEnumerable,
    “Enumerator”, rb_cObject);
    @@ -378,4 +438,5 @@ Init_Enumerator(void)
    rb_define_method(rb_cEnumerator, “initialize”,
    enumerator_initialize, -1);
    rb_define_method(rb_cEnumerator, “each”, enumerator_each, 0);

  • rb_define_method(rb_cEnumerator, “call”, enumerator_call, -2);
    rb_define_method(rb_cEnumerator, “with_index”,
    enumerator_with_index, 0);

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

RubyConfe$B$G;~4V$,6u$$$?$N$G8E$$%a!<%k$rH/7!$7$^$7$?!#e(B

In message “Re: [ruby-dev:29246] Enumerable#each_* and Enumerable#enum_*
on 1.9”
on Wed, 9 Aug 2006 23:07:12 +0900, “U.Nakamura”
[email protected] writes:

|e$B$A$g$C$He(B1.9e$B$Ne(BEnumerablee$B$GM7$s$G$$$F5$IU$$$?$N$G$9$,!"e(B1.9e$B$G$Oe(B
|e$B%V%m%C%/$rH<$o$J$$%$%F%l!<%?8F$S=P$7%a%=%C%I8F$S=P$7e(B([email protected]$Ce(B
|e$B$F$k$N$+$o$+$s$J$$e(B)e$B$Oe(BEnumerable::Enumeratore$B%*%V%8%’%/%H$rJV$9e(B
|e$B$N$K!“85!9e(Benumerator.soe$B$K$”$C$?%$%F%l!<%?8F$S=P$7%a%=%C%I$O$=e(B
|e$B$&$J$C$F$$$^$;$s!#e(B

e$B$*$C$7$c$k$h$&$Ke(BEnumeratore$B$N%a%=%C%I$,%V%m%C%/$J$7$G8F$P$l$ke(B
e$B$He(BEnumerable::Enumeratore$B$rJV$9$o$1$G$9$,!"$3$l$O$I$&$7$F$=$&e(B
e$B$J$C$F$k$s$G$7$g$&$+$M!#$=$s$J$K$&$l$7$$6ILL$,;W$$$D$-$^$;$s!#e(B
e$BF3F~$5$l$?$N$Oe(B

Fri Jul 15 00:11:36 2005 Nobuyoshi N. [email protected]

* enum.c (enumeratorize): create new enumerator for current method if
  no block is given.

* enumerator.c: moved from ext/enumerator.

e$B$J$s$G$9$,!“M}M3$,;W$$=P$;$^$;$s!#9b662qD9$O!”;d$,[email protected]$$=P$7$?e(B
e$B$N$G$O$J$$$+$H$N$3$H$G$9$,!#$"$-$l$k5-21NO$G$9$M!#e(B

e$B$^$"!";d$N5-21NO$,%@%[email protected]$+$i$J$N$G$A$g$C$HCV$$$F$*$/$He(B
e$B$7$F$b!"$3$N$3$H$r5v$9$3$H$G$-$k$h$&$K$J$k$3$H$O!"$?$H$($Pe(B

enum.find.each{|x| x%2==0}

e$B$H$+0lL$G$O2?$r$d$C$F$$$k$N$+$o$+$j$^$;$s!#>/$J$/$H$b!“e(B
Eumerablee$B%b%8%e!<%k$N%a%=%C%I$K$3$N5!G=$rDI2C$7$F$b!”$"$s$^e(B
e$B$j4r$7$/$J$$$s$G$O$J$$$G$7$g$&$+!#e(B

e$B0lJ}!"$?$H$($Pe(B

String.each_line.map{|x| x*2}

e$B$N$h$&$J%1!<%9$O2?$r$d$C$F$$$k$N$+$O$C$-$jJ,$+$j$^$9!#MW$9$ke(B
e$B$K!"MWAG$r$R$H$D$:$DM?$($k$h$&$J%V%m%C%/$N;H$$J}$r$9$k%a%=%Ce(B
e$B%Ie(B(e$B2>$Ke(Beache$B7O$H8F$S$^$7$g$&e(B)e$B0J30$O!"e(BEnumerable::Enumeratore$B$re(B
e$BJV$7$F$bA4A34r$7$/$J$$$H$$$&$3$H$G$9!#e(B

|e$B$3$l$O!"$=$l$>$l$N%$%F%l!<%?8F$S=P$7%a%=%C%I$KBP1~$7$?e(Benum_e$B$Je(B
|e$B$s$H$+%a%=%C%I$,[email protected]$H;W$$$^$9$,!"$3$l$OD>46e(B
|e$B$KH?$9$k5$$,$9$k$N$G!"e(B
|
|(1) e$B3F%$%F%l!<%?8F$S=P$7%a%=%C%I$,%V%m%C%/$J$7$G8F$S=P$5$l$?e(B
| e$B>l9g$Oe(BEnumerable::Enumeratore$B%*%V%8%’%/%H$rJV$9$h$&$K$7!"e(B
|(2) e$B$=$l$i$KBP1~$7$F$$$?e(Benum_*e$B%a%=%C%I$OGQ;$9$ke(B(e$B$^$?$O!"e(B1.9
| e$B$G$OGQ;
$7$J$$$^$G$b7Y9p$9$ke(B)
|
|e$B$H$$$&$N$O$I$&$G$7$g$&$+e(B?

e$B$H$$$&$o$1$G!"e(Benum_*e$B%a%=%C%I$NGQ;_$K$O;[email protected]$7$^$9!#$D$$$G$K!"e(B
eache$B7O$G$J$$%a%=%C%I$+$ie(B

RETURN_ENUMERATOR(obj, argc, argv);

e$B$r<h$j30$7$F$7$^$&$3$H$bDs0F$7$^$9!#$H$$$&$+!"6a$$$&$A$K$d$Ce(B
e$B$A$c$$$^$9$+$iLdBj$,8+$D$+$C$?$i65$($F$/[email protected]$5$$$M!#e(B

                            e$B$^$D$b$He(B e$B$f$-$R$me(B /:|)

[email protected]$G$9!#e(B

At Mon, 23 Oct 2006 07:04:30 +0900,
Yukihiro M. wrote in [ruby-dev:29685]:

enum.find.each{|x| x%2==0}

e$B$H$+0lL$G$O2?$r$d$C$F$$$k$N$+$o$+$j$^$;$s!#>/$J$/$H$b!“e(B
Eumerablee$B%b%8%e!<%k$N%a%=%C%I$K$3$N5!G=$rDI2C$7$F$b!”$"$s$^e(B
e$B$j4r$7$/$J$$$s$G$O$J$$$G$7$g$&$+!#e(B

Enumeratore$B$KC1$J$ke(Beache$B$r<B9T$5$;$F$b4r$7$/$J$$!"$H$$$&$N$OF146$G$9!#e(B
e$BFqFI2=$/$i$$$K$7$+Lr$K$ON)$A$=$&$K$J$$$G$9$7!#$7$+$7!"$=$N;H$$J}$OK\Mhe(B
e$BA[Dj$5$l$k$b$N$+$i$O$+$J$j30$l$F$$$k$s$8$c$J$$$G$7$g$&$+!#e(B

e$B0lJ}!"$?$H$($Pe(B

String.each_line.map{|x| x*2}

e$B$N$h$&$J%1!<%9$O2?$r$d$C$F$$$k$N$+$O$C$-$jJ,$+$j$^$9!#MW$9$ke(B
e$B$K!"MWAG$r$R$H$D$:$DM?$($k$h$&$J%V%m%C%/$N;H$$J}$r$9$k%a%=%Ce(B
e$B%Ie(B(e$B2>$Ke(Beache$B7O$H8F$S$^$7$g$&e(B)e$B0J30$O!"e(BEnumerable::Enumeratore$B$re(B
e$BJV$7$F$bA4A34r$7$/$J$$$H$$$&$3$H$G$9!#e(B

enum.map.with_index e$B$H$+e(B eanum.find.with_index
e$B$N$h$&$Ke(BEnumeratore$B$N%ae(B
e$B%=%C%I$HAH$_9g$o$;$F;H$&$b$s$8$c$J$$$G$7$g$&$+!#e(B

e$B1*1s$J=q$-J}[email protected]$+$i!“JXMx$Je(B(e$B>l9g$b$”$ke(B)e$B$b$N$rGQ;_$9$k$H$$$&$N$O!“e(B
e$B$”$^$j4r$7$/$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:29685] Re: Enumerable#each_* and
Enumerable#enum_* on 1.9”
on Mon, 23 Oct 2006 07:04:30 +0900, Yukihiro M.
[email protected] writes:

|e$B$J$s$G$9$,!“M}M3$,;W$$=P$;$^$;$s!#9b662qD9$O!”;d$,[email protected]$$=P$7$?e(B
|e$B$N$G$O$J$$$+$H$N$3$H$G$9$,!#$"$-$l$k5-21NO$G$9$M!#e(B

e$B$(!<$H!"FI$_$h$&$K$h$C$F$O8m2r$5$l$=$&$J$N$GJdB-!#e(B

e$B!V9b662qD9$K$h$k$H;d$,[email protected]$$=P$7$?$N$G$O$J$$$+$H$$$&$3$H$G$9$,!“e(B
(e$B<+J,$GH/[email protected]$7$?$3$H$r$^$C$?$/;W$$=P$;$J$$$h$&$G$O!”;d$Ne(B) e$B$"e(B
e$B$-$l$k$[$I<e$$5-21NO$G$9$M!W$H$$$&0UL#$G$9!#e(B

e$B4V0c$C$F$b9b662qD9$N5-21NO$,IaDL$8$c$J$$e(B(e$BNI$$J}$K$b0-$$J}$Ke(B
e$B$be(B)e$B$H$$$&0UL#$O$"$j$^$;$s!#$^!"NI$$J}[email protected]$H$O;W$&$1$I!#e(B

e$B$G!"$5$C$-$NB3$-!#e(B

In message “Re: [ruby-dev:29248] Re: Enumerable#each_* and
Enumerable#enum_* on 1.9”
on Thu, 10 Aug 2006 01:12:02 +0900, [email protected] writes:

|> (2) e$B$=$l$i$KBP1~$7$F$$$?e(Benum_e$B%a%=%C%I$OGQ;$9$ke(B(e$B$^$?$O!"e(B1.9
|> e$B$G$OGQ;
$7$J$$$^$G$b7Y9p$9$ke(B)
|
|e$BJL$K$=$N$^$^;D$7$F$
$$$F$b$$$$$s$8$c$J$$$G$7$g$&$+!#e(B

e$B$5$C$-$b=q$-$^$7$?$,!"$J$/$=$&$H;W$$$^$9!#e(Beache$B7O%a%=%C%I$O%Ve(B
e$B%m%C%/$"$j$G%$%F%l!<%H!"%V%m%C%/$J$7$Ge(BEnumeratore$B$H$$$&86B’$G!#e(B

|e$B$D$$$G$K!"e(BEnumerator#enum_ife$B$He(BEnumerable#calle$B$H$$$&$N$bDs0F$7$Fe(B
|e$B$_$^$9!#e(B

[email protected]>!"e(BEnumerable#calle$B$O2?$r$9$k$b$N$+$h$/$o$+$i$J$$$N$G$9$,!#e(B

e$B$$$:$l$K$7$F$b!"$=$&$$$&$N$Oe(Bgeneratore$B$GBP1~$9$Y$-$8$c$J$$$Ge(B
e$B$7$g$&$+$M$(!#$G$-$k$b$N$J$ie(Bgeneratore$B$rAH$9~$$K$7$Fe(B(e$B>l9g$Ke(B
e$B$h$C$F$Oe(BEnumerator
e$B$HE}9g$7$Fe(B)e$B!"e(BEnumerable#mape$B$J$I$NLa$jCM$re(B
lazye$B%j%9%H$K$7$?$$$N$G$9$,!#e(B

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

In message “Re: [ruby-dev:29687] Re: Enumerable#each_* and
Enumerable#enum_* on 1.9”
on Mon, 23 Oct 2006 11:23:27 +0900, “Nobuyoshi N.”
[email protected] writes:

|> enum.find.each{|x| x%2==0}
|>
|> e$B$H$+0lL$G$O2?$r$d$C$F$$$k$N$+$o$+$j$^$;$s!#>/$J$/$H$b!“e(B
|> Eumerablee$B%b%8%e!<%k$N%a%=%C%I$K$3$N5!G=$rDI2C$7$F$b!”$"$s$^e(B
|> e$B$j4r$7$/$J$$$s$G$O$J$$$G$7$g$&$+!#e(B
|
|Enumeratore$B$KC1$J$ke(Beache$B$r<B9T$5$;$F$b4r$7$/$J$$!"$H$$$&$N$OF146$G$9!#e(B
|e$BFqFI2=$/$i$$$K$7$+Lr$K$ON)$A$=$&$K$J$$$G$9$7!#$7$+$7!"$=$N;H$$J}$OK\Mhe(B
|e$BA[Dj$5$l$k$b$N$+$i$O$+$J$j30$l$F$$$k$s$8$c$J$$$G$7$g$&$+!#e(B

e$B$($($H!">e$N%3!<%I$,!VK\MhA[Dj$5$l$k$b$N!W$G$J$$$3$H$OF10U$7e(B
e$B$^$9!#5$$K$7$F$$$k$N$O!VK\MhA[Dj$5$l$k$b$N!W$H$O$J$K$+$H$$$&e(B
e$B$3$H$G$9!#>/$J$/$H$b;d$O;W$$$D$+$J$$$s$G$9$h$M!#e(B

|> String.each_line.map{|x| x*2}
|>
|> e$B$N$h$&$J%1!<%9$O2?$r$d$C$F$$$k$N$+$O$C$-$jJ,$+$j$^$9!#MW$9$ke(B
|> e$B$K!"MWAG$r$R$H$D$:$DM?$($k$h$&$J%V%m%C%/$N;H$$J}$r$9$k%a%=%Ce(B
|> e$B%Ie(B(e$B2>$Ke(Beache$B7O$H8F$S$^$7$g$&e(B)e$B0J30$O!"e(BEnumerable::Enumeratore$B$re(B
|> e$BJV$7$F$bA4A34r$7$/$J$$$H$$$&$3$H$G$9!#e(B
|
|enum.map.with_index e$B$H$+e(B eanum.find.with_index e$B$N$h$&$Ke(BEnumeratore$B$N%ae(B
|e$B%=%C%I$HAH$_9g$o$;$F;H$&$b$s$8$c$J$$$G$7$g$&$+!#e(B

enum.map{}.with_indexe$B$H$+$J$i$H$b$+$/!“e(Benum.map.with_indexe$B$Ke(B
e$B$J$s$N0UL#$,$”$k$N$+$H!#0UL#E*$K$Oe(Benum.to_a.each_with_index
e$B$HF1$8$o$1$G$9$+$i!#e(B

|e$B1*1s$J=q$-J}[email protected]$+$i!“JXMx$Je(B(e$B>l9g$b$”$ke(B)e$B$b$N$rGQ;_$9$k$H$$$&$N$O!“e(B
|e$B$”$^$j4r$7$/$J$$$h$&$J5$$,$7$^$9!#e(B

e$B!VJXMx$J>l9g$,;W$$$D$+$J$$$+$iGQ;$7$h$&[email protected]$C$F$k$o$1$G$9e(B
e$B$+$i!"!VJXMx$J>l9g$,$"$k!W$J$iGQ;
$7$^$;$s!#e(B

                            e$B$^$D$b$He(B e$B$f$-$R$me(B /:|)

e$B$3$s$K$A$O!"$J$+$`$ie(B(e$B$&e(B)e$B$G$9!#e(B

In message “[ruby-dev:29688] Re: Enumerable#each_* and Enumerable#enum_*
on 1.9”
on Oct.23,2006 13:17:39, [email protected] wrote:
| |> String.each_line.map{|x| x2}
| |>
| |> e$B$N$h$&$J%1!<%9$O2?$r$d$C$F$$$k$N$+$O$C$-$jJ,$+$j$^$9!#MW$9$ke(B
| |> e$B$K!"MWAG$r$R$H$D$:$DM?$($k$h$&$J%V%m%C%/$N;H$$J}$r$9$k%a%=%Ce(B
| |> e$B%Ie(B(e$B2>$Ke(Beache$B7O$H8F$S$^$7$g$&e(B)e$B0J30$O!"e(BEnumerable::Enumeratore$B$re(B
| |> e$BJV$7$F$bA4A34r$7$/$J$$$H$$$&$3$H$G$9!#e(B
| |
| |enum.map.with_index e$B$H$+e(B eanum.find.with_index e$B$N$h$&$Ke(BEnumeratore$B$N%ae(B
| |e$B%=%C%I$HAH$_9g$o$;$F;H$&$b$s$8$c$J$$$G$7$g$&$+!#e(B
|
| enum.map{}.with_indexe$B$H$+$J$i$H$b$+$/!“e(Benum.map.with_indexe$B$Ke(B
| e$B$J$s$N0UL#$,$”$k$N$+$H!#0UL#E
$K$Oe(Benum.to_a.each_with_index
| e$B$HF1$8$o$1$G$9$+$i!#e(B

e$B$$$d$$$d!“e(Beache$B$He(Bmape$B$K$OLa$jCM$,0c$&$H$$$&7hDjE*$J:9$,$”$j$^$9!#e(B
e$B$h$C$F!"e(B
p enum.map.with_index{|e,i|…} #(A)
e$B$H=q$/$3$H$,$G$-$J$/$J$k$H!"F1$8$3$H$r<B8=$9$k$?$a$K$O!"e(B
a = []; enum.to_a.each_with_index{|e,i|a<<…}; p a #(B)
e$B$^$?$Oe(B
p enum.to_enum(:map).with_index{|e,i|…} #©
e$B$H$$$&5-=R$,I,MW$K$J$j$^$9!#e(B

e$B$=$b$=$b!“e(BEnumerable::Enumeratore$B$O!“FbItE*$Ge(Beache$B$r7h$a$&$A$Ge(B
e$B;H$&%V%m%C%/IU$-%a%=%C%I$Ge(Beache$B0J30$r;H$C$F$[$7$$>l9g$,$”$k$+e(B
[email protected]$HM}2r$7$F$$$^$9!#e(B
e$B$D$^$j!“e(B(B)e$B$N$h$&$K=q$/$N$,%”%[[email protected]$+$ie(B©e$B$H=q$1$k$h$&$Ke(B
e$B$7$?!”$H$$$&$3$H$G$9$M!#e(B
e$B$=$7$F!"e(B1.9e$B$N8=>u$N;EMM$O!“e(B©e$B$H$$$A$$$A=q$/$h$je(B(A)e$B$H=q$1$?J}e(B
e$B$,4r$7$$$8$c$s!”$H$$$&[email protected]$H;W$C$F$$$?$N$G$9$,e(B…

| |e$B1*1s$J=q$-J}[email protected]$+$i!“JXMx$Je(B(e$B>l9g$b$”$ke(B)e$B$b$N$rGQ;$9$k$H$$$&$N$O!“e(B
| |e$B$”$^$j4r$7$/$J$$$h$&$J5$$,$7$^$9!#e(B
|
| e$B!VJXMx$J>l9g$,;W$$$D$+$J$$$+$iGQ;
$7$h$&[email protected]$C$F$k$o$1$G$9e(B
| e$B$+$i!"!VJXMx$J>l9g$,$"$k!W$J$iGQ;_$7$^$;$s!#e(B

e$B$3$s$J$3$H$K;H$C$?$j$7$F$^$9!#JXMx$G$9!#e(B
http://www.garbagecollect.jp/~usa/d/200608a.html#id20060810_P1

e$B$=$l$G$O!#e(B

In message “Re: [ruby-dev:29689] Re: Enumerable#each_* and
Enumerable#enum_* on 1.9”
on Mon, 23 Oct 2006 15:10:58 +0900, “U.Nakamura”
[email protected] writes:
|
|e$B$3$s$K$A$O!"$J$+$`$ie(B(e$B$&e(B)e$B$G$9!#e(B
|
|In message “[ruby-dev:29688] Re: Enumerable#each_* and Enumerable#enum_* on 1.9”
| on Oct.23,2006 13:17:39, [email protected] wrote:
|| |> String.each_line.map{|x| x2}
|| |>
|| |> e$B$N$h$&$J%1!<%9$O2?$r$d$C$F$$$k$N$+$O$C$-$jJ,$+$j$^$9!#MW$9$ke(B
|| |> e$B$K!"MWAG$r$R$H$D$:$DM?$($k$h$&$J%V%m%C%/$N;H$$J}$r$9$k%a%=%Ce(B
|| |> e$B%Ie(B(e$B2>$Ke(Beache$B7O$H8F$S$^$7$g$&e(B)e$B0J30$O!"e(BEnumerable::Enumeratore$B$re(B
|| |> e$BJV$7$F$bA4A34r$7$/$J$$$H$$$&$3$H$G$9!#e(B
|| |
|| |enum.map.with_index e$B$H$+e(B eanum.find.with_index e$B$N$h$&$Ke(BEnumeratore$B$N%ae(B
|| |e$B%=%C%I$HAH$_9g$o$;$F;H$&$b$s$8$c$J$$$G$7$g$&$+!#e(B
||
|| enum.map{}.with_indexe$B$H$+$J$i$H$b$+$/!“e(Benum.map.with_indexe$B$Ke(B
|| e$B$J$s$N0UL#$,$”$k$N$+$H!#0UL#E
$K$Oe(Benum.to_a.each_with_index
|| e$B$HF1$8$o$1$G$9$+$i!#e(B
|
|e$B$$$d$$$d!“e(Beache$B$He(Bmape$B$K$OLa$jCM$,0c$&$H$$$&7hDjE*$J:9$,$”$j$^$9!#e(B
|e$B$h$C$F!"e(B
| p enum.map.with_index{|e,i|…} #(A)
|e$B$H=q$/$3$H$,$G$-$J$/$J$k$H!"F1$8$3$H$r<B8=$9$k$?$a$K$O!"e(B
| a = []; enum.to_a.each_with_index{|e,i|a<<…}; p a #(B)
|e$B$^$?$Oe(B
| p enum.to_enum(:map).with_index{|e,i|…} #©
|e$B$H$$$&5-=R$,I,MW$K$J$j$^$9!#e(B
|
|
|e$B$=$b$=$b!"e(BEnumerable::Enumeratore$B$O!“FbItE*$Ge(Beache$B$r7h$a$&$A$Ge(B
|e$B;H$&%V%m%C%/IU$-%a%=%C%I$Ge(Beache$B0J30$r;H$C$F$[$7$$>l9g$,$”$k$+e(B
|[email protected]$HM}2r$7$F$$$^$9!#e(B

e$BF10U$7$^$9!#e(B

|e$B$D$^$j!“e(B(B)e$B$N$h$&$K=q$/$N$,%”%[[email protected]$+$ie(B©e$B$H=q$1$k$h$&$Ke(B
|e$B$7$?!"$H$$$&$3$H$G$9$M!#e(B
|e$B$=$7$F!"e(B1.9e$B$N8=>u$N;EMM$O!“e(B©e$B$H$$$A$$$A=q$/$h$je(B(A)e$B$H=q$1$?J}e(B
|e$B$,4r$7$$$8$c$s!”$H$$$&[email protected]$H;W$C$F$$$?$N$G$9$,e(B…

(B)e$B$N$h$&$K=q$/$N$,%"%[$_$?$$e(B(A)e$B$NJ}$,NI$$$H$$$&$N$OJ,$+$i$Je(B
e$B$$$G$b$"$j$^$;$s!#$H$O$$$(!"e([email protected][email protected]$1$N$?$a$Ke(B
mape$B$,e(BEnumeratore$B$rJV$9$h$&$K$9$k$C$F$N$b$J$s$+JQ$J5$$,$7$^$9!#e(B
e$B$=$b$=$b%V%m%C%/$r>JN,$7$?e(Bmape$B$C$F$J$K$h$C$FOC$K$J$j$^$9$7!#e(B

e$BMWAG$=$N$b$N$re(Bmape$B$9$ke(B(e$B$D$^$j%V%m%C%/$N>JN,$Oe(B{|x|x}e$B$HF1$8e(B)
e$B$He(B
e$B2r<a$9$k$J$i$Pe(B(e$B$=$N2r<a$O<[email protected]$H;W$$$^$9$,e(B)e$B!"e(Bmape$B$Oe(B
Enumeratore$B$rJV$7$F$O$$$1$J$$!"DL>o$Ne(Bmape$B$HF1$8$b$N$rJV$5$J$/e(B
e$B$F$O$$$1$^$;$s!#%V%m%C%/IU$-$Ne(Bmape$B$,e(BEnumeratore$B$rJV$5$J$$0J>e!“e(B
e$B3FMWAG$rJV$9e(BEnumeratore$B$,M_$7$/$F$b!”$=$NL>A0$O>/$J$/$H$be(Bmap
e$B$G$O$J$$$H;W$$$^$9!#$A$g$C$H9M$($k$He(Bentriese$B$,;W$$$D$-$^$9$,!"e(B
e$B:#$Oe(Bto_ae$B$NJLL>$G$9$M!#e(B

|| e$B!VJXMx$J>l9g$,;W$$$D$+$J$$$+$iGQ;$7$h$&[email protected]$C$F$k$o$1$G$9e(B
|| e$B$+$i!"!VJXMx$J>l9g$,$"$k!W$J$iGQ;
$7$^$;$s!#e(B
|
|e$B$3$s$J$3$H$K;H$C$?$j$7$F$^$9!#JXMx$G$9!#e(B
|http://www.garbagecollect.jp/~usa/d/200608a.html#id20060810_P1

e$B$?$H$($P$3$&$$$&$3$H$G$9$h$M!#e(B

ARGF.binmode.each_byte.with_index{|b, i|
print ‘%08x:’ % i if i % 16 == 0
print ’ %02x’ % b
puts if i % 16 == 15
}

e$B$3$&$$$&$N$G$I$&$+$H;W$$$^$9!#e(B

ARGF.binmode.bytes.with_index{|b, i|
print ‘%08x:’ % i if i % 16 == 0
print ’ %02x’ % b
puts if i % 16 == 15
}

e$B$b$C$HC;$$$7!#$b$C$H$be(Bbytese$B$,$J$K$rJV$9$Y$-$+$K$Oe(Bruby-coree$BJ}e(B
e$BLL$G$b$d$d0[[email protected]$,$"$k$h$&$G$9$,!#$b$&$A$g$C$HCV$-49$(2DG=$G$Je(B
e$B$$Nc$O$J$$$+$J$"!#e(B

                            e$B$^$D$b$He(B e$B$f$-$R$me(B /:|)

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

In message “Re: [ruby-dev:29690] Re: Enumerable#each_* and
Enumerable#enum_* on 1.9”
on Mon, 23 Oct 2006 16:38:52 +0900, Yukihiro M.
[email protected] writes:

|e$BMWAG$=$N$b$N$re(Bmape$B$9$ke(B(e$B$D$^$j%V%m%C%/$N>JN,$Oe(B{|x|x}e$B$HF1$8e(B) e$B$He(B
|e$B2r<a$9$k$J$i$Pe(B(e$B$=$N2r<a$O<[email protected]$H;W$$$^$9$,e(B)e$B!"e(Bmape$B$Oe(B
|Enumeratore$B$rJV$7$F$O$$$1$J$$!"DL>o$Ne(Bmape$B$HF1$8$b$N$rJV$5$J$/e(B
|e$B$F$O$$$1$^$;$s!#%V%m%C%/IU$-$Ne(Bmape$B$,e(BEnumeratore$B$rJV$5$J$$0J>e!“e(B
|e$B3FMWAG$rJV$9e(BEnumeratore$B$,M_$7$/$F$b!”$=$NL>A0$O>/$J$/$H$be(Bmap
|e$B$G$O$J$$$H;W$$$^$9!#$A$g$C$H9M$($k$He(Bentriese$B$,;W$$$D$-$^$9$,!"e(B
|e$B:#$Oe(Bto_ae$B$NJLL>$G$9$M!#e(B

[email protected]$$2a$.$+$J!#%V%m%C%/$J$7$N%$%F%l!<%?%a%=%C%I$Ke(B
with_indexe$B$rIU$1$i$l$k$3$H$,[email protected]$14r$7$$$+$C$FOC$J$s$G$7$ge(B
e$B$&$M!#e(Bmape$B$K$O0cOB46$,$"$k$7!“e(B.with_indexe$B0U30$K;H$$$_$A$,;W$$e(B
e$B$D$+$J$$$N$G!”$A$g$C$H5?LdId$,$D$/!"$/$i$$$G$7$g$&$+!#e(B

e$B$=$&9M$($k$H%V%m%C%/$r>JN,$5$l$?;~$KJV$5$l$k$b$N$O$$$C$=$N$3e(B
e$B$He(Bwith_index e$B0J30$N%a%=%C%I$r;}$?$J$$$H$+$NJ}$,$o$+$j$d$9$$e(B
e$B$+$b$7$l$^$;$s!#e(B

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs