e$B1sF#$H?=$7$^$9!#e(B
1.9 e$B$Ge(B Enumearble#each_with_index e$B$,e(B yield
e$B$7$F$/$kG[Ns$,JQ992DG=$G$9!#e(B
e$BL5BL$KJXMx$+$b$7$l$J$$$N$G$9$,!";EMM$G$7$g$&$+!#e(B
$ ./ruby -e ‘%w(a b c).each_with_index {|r| p r; r.push r[0] }’
[“a”, 0]
[“b”, 1, “a”]
[“c”, 2, “a”, “b”]
e$B$3$NG[Ns$r=L$a$?>l9g!“M}O@>e%”%/%;%90cH?$9$k2DG=@-$,$"$k$h$&$J5$$,$7$^$9!#e(B
(e$B8=<BE*$K$OH/>I$7$J$$$H;W$$$^$9$,e(B)
$ ./ruby -e ‘%w(a b c).each_with_index {|r| p r; r.pop }’
[“a”, 0]
[“b”]
[]
e$B$H$j$"$($:$3$NG[Ns$re(B freeze e$B$5$;$k%Q%C%A$G$9!#e(B
Index: enum.c
— enum.c (revision 13827)
+++ enum.c (working copy)
@@ -1327,6 +1327,7 @@
RETURN_ENUMERATOR(obj, argc, argv);
memo = rb_ary_new3(2, Qnil, INT2FIX(0));
- rb_ary_freeze(memo);
rb_block_call(obj, id_each, argc, argv, each_with_index_i, memo);
return obj;
}
e$B1sF#$G$9!#e(B
1.9 e$B$Ge(B Enumearble#each_with_index e$B$,e(B yield e$B$7$F$/$kG[Ns$,JQ992DG=$G$9!#e(B
e$BL5BL$KJXMx$+$b$7$l$J$$$N$G$9$,!";EMM$G$7$g$&$+!#e(B
e$BG[Ns$,JQ992DG=$G$"$k$3$H$h$j!";H$$$^$o$5$l$F$$$k$3$H$NJ}$,LdBj$J$N$+$be(B
e$BCN$l$^$;$s!#0J2<$O;EMM$G$7$g$&$+!#e(B
$ ./ruby -e ‘p %w(a b c).each_with_index.to_a’
[[“c”, 3], [“c”, 3], [“c”, 3]]
e$B$A$J$_$Ke(B each.with_index
e$B$N>l9g$O;d$N4|BTDL$j$N7k2L$K$J$j$^$7$?!#e(B
$ ./ruby -e ‘p %w(a b c).each.with_index.to_a’
[[“a”, 0], [“b”, 1], [“c”, 2]]
each_with_index e$B$Oe(B each.with_index
e$B$HEy2A$G$"$k$H;W$$$?$$$G$9!#e(B
e$B1sF#$G$9!#e(B
1.9 e$B$Ge(B Enumearble#each_with_index e$B$,e(B yield e$B$7$F$/$kG[Ns$,JQ992DG=$G$9!#e(B
e$BL5BL$KJXMx$+$b$7$l$J$$$N$G$9$,!";EMM$G$7$g$&$+!#e(B
e$B$3$N7o!“e(Brevision 13833
e$B$GBP1~$$$?$@$$$?$h$&$G$”$j$,$H$&$4$6$$$^$9!#e(B
e$B$7$+$78e$G5$$,$D$$$?$N$G$9$,!“0J2<$N$h$&$J5sF0$N0c$$$b$”$j$^$7$?!#e(B
$ ./ruby -e ‘%w(a b c).each_with_index {|x| p x }’
[“a”,0]
[“b”,1]
[“c”,2]
$ ./ruby -e ‘%w(a b c).each.with_index {|x| p x }’
“a”
“b”
“c”
13833 e$B$K2C$($F0J2<$N$h$&$K$9$k$H$h$$$H;W$$$^$9!#e(B
Index: enum.c
— enum.c (revision 13846)
+++ enum.c (working copy)
@@ -1295,7 +1295,7 @@
{
long n = (*(VALUE *)memo)++;
- return rb_yield(rb_ary_new3(2, val, INT2NUM(n)));
- return rb_yield_values(2, val, INT2NUM(n));
}
/*