# \[Feature:trunk\] with\_index\_from

**URL:** <https://www.ruby-forum.com/t/feature-trunk-with-index-from/159538>\
**Category:** Development\
**Created:** [February 5, 2009, 3:21pm UTC](https://www.ruby-forum.com/t/feature-trunk-with-index-from/159538 "2009-02-05T15:21:29Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Yusuke\_ENDOH](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/c89c15/32.png) [@Yusuke\_ENDOH](https://www.ruby-forum.com/u/Yusuke_ENDOH)\
**Post date:** [February 5, 2009, 3:21pm UTC](https://www.ruby-forum.com/t/feature-trunk-with-index-from/159538/1 "2009-02-05T15:21:29Z")

</div>

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

with\_index  
e$B$N3+;O%$%s%G%C%/%9$r;XDj$G$-$k%P!\<%8%g%s$,$"$k$HJXMx$@$He(B  
e$B;W$$$^$9!#e(B

$ ./ruby -e ‘p %w(a b c).map.with\_index\_from(1) {|c, i| [c, i] }’  
[[“a”, 1], [“b”, 2], [“c”, 3]]

e$B%$%s%G%C%/%9$r;XDj$7$?$$M}M3$H$7$F$O!"e(B

- e$B%f!\<%6%$%s%?!\<%U%'%$%9$G$Oe(B 1 e$BHVL$+$i?t$($k$3$H$,B?$$e(B  
(e$B;2\>He(B) [配列の先頭要素が「0番目」であることは気持ち悪いか…「N番目」という言葉を考察してみる - http://rubikitch.com/に移転しました](http://d.hatena.ne.jp/rubikitch/20080524/1211627661)

- e$BNs$d9TNs$Ne(B 0 e$BHVL$re(B (e$B=i4|CM$J$I$H$7$Fe(B)  
e$BFCJL07$$$9$k%“%k%4%j%:%`$,$”$ke(B  
(e$B;2\>He(B) [レーベンシュタイン距離 - まめめも](http://d.hatena.ne.jp/ku-ma-me/20081026/p2)

- e$B@hF,$rHt$P$7$F%$%s%G%C%/%9IU$-%$%F%l!\<%H$9$k$N$,4JC1$K$J$ke(B  
(e$BNce(B) ary.each\_with\_index {|x, i| next if i == 0; … } e$B$de(B  
ary.drop(1).each\_with\_index {|x, i| i += 1; … } e$B$,e(B  
ary.drop(1).each\_with\_index\_from(1) {|x, y| … }  
e$B$K$J$C$F$9$C$-$je(B

e$B$J$I$,$"$j$^$9!#e(B

e$B0J2\<$N%Q%C%A$Oe(B 3 e$B$D$N%a%=%C%I$rDI2C$7$^$9!#e(B

- Enumerator#each\_with\_index\_from(n)
- Enumerator#with\_index\_from(n)
- Enumerable#each\_with\_index\_from(n)

e$B$I$&$G$7$g$&$+!#e(B

# Index: enumerator.c

— enumerator.c (revision 22080)  
+++ enumerator.c (working copy)  
@@ -397,31 +397,20 @@  
}

static VALUE  
-enumerator\_with\_index\_i(VALUE val, VALUE \*memo)  
+enumerator\_with\_index\_i(VALUE val, long \*memo)  
{  
val = rb\_yield\_values(2, val, INT2FIX(\*memo));  
++\*memo;  
return val;  
}

-/\*

- 
  - call-seq:

- 
  - e.with\_index {|(\*args), idx| … }

- 
  - e.with\_index

- 
  - 

- 
  - Iterates the given block for each element with an index, which

- 
  - start from 0. If no block is given, returns an enumerator.

- 
  - 

- \*/  
static VALUE  
-enumerator\_with\_index(VALUE obj)  
+enumerator\_with\_index\_core(VALUE obj, long memo)  
{  
struct enumerator \*e;

- VALUE memo = 0;  
int argc = 0;  
VALUE \*argv = 0;

- RETURN\_ENUMERATOR(obj, 0, 0);  
e = enumerator\_ptr(obj);  
if (e-\>args) {  
argc = RARRAY\_LEN(e-\>args);  
@@ -431,7 +420,39 @@  
enumerator\_with\_index\_i, (VALUE)&memo);  
}

+/\*

- 
  - call-seq:

- 
  - e.with\_index {|(\*args), idx| … }

- 
  - e.with\_index

- 
  - 

- 
  - Iterates the given block for each element with an index, which

- 
  - starts from 0. If no block is given, returns an enumerator.

- 
  - 

- \*/  
static VALUE  
+enumerator\_with\_index(VALUE obj)  
+{
- RETURN\_ENUMERATOR(obj, 0, 0);
- return enumerator\_with\_index\_core(obj, 0);  
+}
- 

+/\*

- 
  - call-seq:

- 
  - e.with\_index\_from(n) {|(\*args), idx| … }

- 
  - e.with\_index\_from(n)

- 
  - 

- 
  - Iterates the given block for each element with an index, which

- 
  - starts from _n_. If no block is given, returns an enumerator.

- 
  - 

- \*/  
+static VALUE  
+enumerator\_with\_index\_from(VALUE obj, VALUE val)  
+{
- RETURN\_ENUMERATOR(obj, 1, &val);
- return enumerator\_with\_index\_core(obj, NUM2LONG(val));  
+}
- 

+static VALUE  
enumerator\_with\_object\_i(VALUE val, VALUE memo)  
{  
return rb\_yield\_values(2, val, memo);  
@@ -842,8 +863,10 @@  
rb\_define\_method(rb\_cEnumerator, “initialize\_copy”,  
enumerator\_init\_copy, 1);  
rb\_define\_method(rb\_cEnumerator, “each”, enumerator\_each, 0);  
rb\_define\_method(rb\_cEnumerator, “each\_with\_index”,  
enumerator\_with\_index, 0);

- rb\_define\_method(rb\_cEnumerator, “each\_with\_index\_from”,  
enumerator\_with\_index\_from, 1);  
rb\_define\_method(rb\_cEnumerator, “each\_with\_object”,  
enumerator\_with\_object, 1);  
rb\_define\_method(rb\_cEnumerator, “with\_index”,  
enumerator\_with\_index, 0);
- rb\_define\_method(rb\_cEnumerator, “with\_index\_from”,  
enumerator\_with\_index\_from, 1);  
rb\_define\_method(rb\_cEnumerator, “with\_object”,  
enumerator\_with\_object, 1);  
rb\_define\_method(rb\_cEnumerator, “next”, enumerator\_next, 0);  
rb\_define\_method(rb\_cEnumerator, “rewind”, enumerator\_rewind, 0);  
Index: enum.c  
===================================================================  
— enum.c (revision 22080)  
+++ enum.c (working copy)  
@@ -1425,7 +1425,34 @@  
return obj;  
}

+/\*

- 
  - call-seq:

- 
  - 

```
enum.each_with_index_from(n) {|obj, i| block } -> enum

```

- 
  - 

- 
  - Calls _block_ with two arguments, the item and its index,

- 
  - for each item in _enum_. The index starts from _n_.

- 
  - Given arguments are passed through to #each().

- 
  - 

- 
  - 

```
hash = Hash.new

```

- 
  - 

```
%w(cat dog wombat).each_with_index_from(1) {|item, index|

```

- 
  - 

```
  hash[item] = index

```

- 
  - 

```
}

```

- 
  - 

```
hash #=> {"cat"=>1, "dog"=>2, "wombat"=>3}

```

- 
  - 

- \*/

+static VALUE  
+enum\_each\_with\_index\_from(VALUE obj, VALUE val)  
+{

- long memo = NUM2LONG(val);
- 
- RETURN\_ENUMERATOR(obj, 1, &val);
- 
- rb\_block\_call(obj, id\_each, 0, 0, each\_with\_index\_i, (VALUE)&memo);
- return obj;  
+}
- 
- 

/\*

- call-seq:
- 

```
enum.reverse_each {|item| block }

```

@@ -1845,6 +1872,7 @@  
rb\_define\_method(rb\_mEnumerable, “member?”, enum\_member, 1);  
rb\_define\_method(rb\_mEnumerable, “include?”, enum\_member, 1);  
rb\_define\_method(rb\_mEnumerable, “each\_with\_index”,  
enum\_each\_with\_index, -1);

- rb\_define\_method(rb\_mEnumerable, “each\_with\_index\_from”,  
enum\_each\_with\_index\_from, 1);  
rb\_define\_method(rb\_mEnumerable, “reverse\_each”, enum\_reverse\_each,  
-1);  
rb\_define\_method(rb\_mEnumerable, “zip”, enum\_zip, -1);  
rb\_define\_method(rb\_mEnumerable, “take”, enum\_take, 1);

---

<div class="post-metadata">

**Author:** ![Yusuke\_ENDOH](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/c89c15/32.png) [@Yusuke\_ENDOH](https://www.ruby-forum.com/u/Yusuke_ENDOH)\
**Post date:** [February 5, 2009, 4:47pm UTC](https://www.ruby-forum.com/t/feature-trunk-with-index-from/159538/2 "2009-02-05T16:47:26Z")

</div>

At Thu, 5 Feb 2009 23:18:49 +0900,  
Yusuke ENDOH wrote:

> with\_index ã®é–‹å§‹ã‚¤ãƒ³ãƒ‡ãƒƒã‚¯ã‚¹ã‚’æŒ‡å®šã§ãã‚‹ãƒãƒ¼ã‚¸ãƒ§ãƒ³ãŒã‚ã‚‹ã¨ä¾¿åˆ©ã ã¨  
> æ€ã„ã¾ã™ã€‚
> 
> $ ./ruby -e ‘p %w(a b c).map.with\_index\_from(1) {|c, i| [c, i] }’  
> [[“a”, 1], [“b”, 2], [“c”, 3]]

ã€€æ–°ã—ã„ãƒ¡ã‚½ãƒƒãƒ‰ã‚’è¿½åŠ ã™ã‚‹ã®ã¯å¤§ä»°ãªæ°—ã‚‚ã—ã¾ã™ã€‚æ—¢å­˜ã®  
(each\_)with\_index ã«çœç•¥å¯èƒ½å¼•æ•°ã‚’è¿½åŠ ã™ã‚‹ã®ã¯ã©ã†ã§ã—ã‚‡ã†ã€‚

with\_index(offset = 0)

ã€€index ã¨ã„ã†åå‰ã‹ã‚‰ä»Šå¾Œå¢—åˆ†ç­‰ã‚’è¿½åŠ ã™ã‚‹ã“ã¨ã¯è€ƒãˆã«ãã„  
ã®ã§ã€å”¯ä¸€ã®å¼•æ•°ãŒåˆæœŸå€¤(ã‚ªãƒ•ã‚»ãƒƒãƒˆ)ã¨ã„ã†ã®ã¯ç´å¾—ã§ãã‚‹ã®  
ã§ã¯ãªã„ã‹ã¨æ€ã„ã¾ã™ãŒã€ã©ã†ã§ã—ã‚‡ã†ã€‚

---

<div class="post-metadata">

**Author:** ![Yusuke\_ENDOH](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/c89c15/32.png) [@Yusuke\_ENDOH](https://www.ruby-forum.com/u/Yusuke_ENDOH)\
**Post date:** [February 5, 2009, 5:00pm UTC](https://www.ruby-forum.com/t/feature-trunk-with-index-from/159538/3 "2009-02-05T17:00:59Z")

</div>

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

2009/02/06 0:43 Akinori MUSHA [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> (each\_)with\_index e$B$K\>JN,2DG=0z?t$rDI2C$9$k$N$O$I$&$G$7$g$&!#e(B
> 
> ```
> with_index(offset = 0)
> 
> ```
> 
> index e$B$H$$$&L\>A0$+$i:#8eA}J,Ey$rDI2C$9$k$3$H$O9M$($K$/$$e(B  
> e$B$N$G!“M#0l$N0z?t$,=i4|CMe(B(e$B%\*%U%;%C%He(B)e$B$H$$$&$N$OG\<F@$G$-$k$Ne(B  
> e$B$G$O$J$$$+$H;W$$$^$9$,!”$I$&$G$7$g$&!#e(B

with\_index e$B$O$=$l$GLdBj$J$$$s$G$9$,!"0d48$J$,$ie(B each\_with\_index  
e$B$O0z?t$re(B  
each  
e$B$K4]Ej$2$9$k$H8@$&;EMM$K$J$C$F$$$k$N$G!“8\_49@-$NLdBj$,$”$j$^$9!#e(B

$ ruby19 -rstringio -e  
‘StringIO.new(“foo|bar|baz”).each\_with\_index(“|”) {|s, i| p [s, i] }’  
[“foo|”, 0]  
[“bar|”, 1]  
[“baz”, 2]

e$B$I$&$9$k$N$,0lHV9,$;$G$7$g$&$M!#e(B

---

<div class="post-metadata">

**Author:** ![Yusuke\_ENDOH](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/c89c15/32.png) [@Yusuke\_ENDOH](https://www.ruby-forum.com/u/Yusuke_ENDOH)\
**Post date:** [February 6, 2009, 10:40am UTC](https://www.ruby-forum.com/t/feature-trunk-with-index-from/159538/4 "2009-02-06T10:40:29Z")

</div>

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

In message “Re: [ruby-dev:37928] Re: [Feature:trunk] with\_index\_from”  
on Fri, 6 Feb 2009 12:04:30 +0900, “Akinori MUSHA”  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) writes:

|e$B!!$7$+$7!"e(B each\_with\_index\_from e$B$H$$$&L\>A0$OD9$9$.$k$H;W$$$^$9!#e(B  
|e$B$^$?e(B each\_with\_index e$B\<+BN!“e(B Enumerator e$B$,F3F~$5$l$?:#$H$J$C$F$Oe(B  
|each.with\_index e$B$h$j$b\<c43\<B9T8zN($,$h$$$3$H$r=|$1$PB8:\_0U5A$,e(B  
|e$BGv$$$G$9$M!#e(B  
|  
|e$B!!$3$3$O!“e(B with\_index e$B$K$@$10z?t$rDI2C$7$Fe(B each\_with\_index e$B$Oe(B  
|e$B$=$N$^$^$K$7$F$O$I$&$G$7$g$&!#e(B  
|  
|StringIO.new(“foo|bar|baz”).each(”|”).with\_index(1) { … }  
|  
|e$B!!$A$g$C$H6E$C$?$3$H$r$7$?$1$l$Pe(B Enumerator e$B7PM3$G9T$C$F$M!"e(B  
|e$B$H$$$&%9%?%s%9$O0-$/$O$J$$$H;W$$$^$9!#e(B

each\_with\_indexe$B$OJ|CV!#e(BEnumerator#with\_indexe$B$NJ}$G\<jEv$F$9$ke(B  
e$BJ}$K;?@.$7$^$9!#$,!"8=;~E@$G$O4J7i$Je(Bwith\_index(1)e$B$K$9$k$N$+!"e(B  
e$B$h$jL@3N$Je(Bwith\_index\_from(1)e$B$K$9$k$N$+$O7hCG$G$-$^$;$s!#$I$Ce(B  
e$B$A$,$h$$$G$7$g$&$M$(!#e(B

---

<div class="post-metadata">

**Author:** ![Yusuke\_ENDOH](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/c89c15/32.png) [@Yusuke\_ENDOH](https://www.ruby-forum.com/u/Yusuke_ENDOH)\
**Post date:** [February 6, 2009, 4:05am UTC](https://www.ruby-forum.com/t/feature-trunk-with-index-from/159538/5 "2009-02-06T04:05:50Z")

</div>

At Fri, 6 Feb 2009 00:58:59 +0900,  
Yusuke ENDOH wrote:

> with\_index ã¯ãã‚Œã§å•é¡Œãªã„ã‚“ã§ã™ãŒã€éºæ†¾ãªãŒã‚‰ each\_with\_index ã¯å¼•æ•°ã‚’  
> each ã«ä¸¸æŠ•ã’ã™ã‚‹ã¨è¨€ã†ä»•æ§˜ã«ãªã£ã¦ã„ã‚‹ã®ã§ã€äº’æ›æ€§ã®å•é¡ŒãŒã‚ã‚Šã¾ã™ã€‚
> 
> $ ruby19 -rstringio -e  
> ‘StringIO.new(“foo|bar|baz”).each\_with\_index("|") {|s, i| p [s, i] }’  
> [“foo|”, 0]  
> [“bar|”, 1]  
> [“baz”, 2]
> 
> ã©ã†ã™ã‚‹ã®ãŒä¸€ç•ªå¹¸ã›ã§ã—ã‚‡ã†ã­ã€‚

ã€€ã‚ã‚ã€ãã®ä»•æ§˜ã¯å¿˜ã‚Œã¦ã„ã¾ã—ãŸã€‚

ã€€ã—ã‹ã—ã€ each\_with\_index\_from ã¨ã„ã†åå‰ã¯é•·ã™ãŽã‚‹ã¨æ€ã„ã¾ã™ã€‚  
ã¾ãŸ each\_with\_index è‡ªä½“ã€ Enumerator ãŒå°Žå…¥ã•ã‚ŒãŸä»Šã¨ãªã£ã¦ã¯  
each.with\_index ã‚ˆã‚Šã‚‚è‹¥å¹²å®Ÿè¡ŒåŠ¹çŽ‡ãŒã‚ˆã„ã“ã¨ã‚’é™¤ã‘ã°å­˜åœ¨æ„ç¾©ãŒ  
è–„ã„ã§ã™ã­ã€‚

ã€€ã“ã“ã¯ã€ with\_index ã«ã ã‘å¼•æ•°ã‚’è¿½åŠ ã—ã¦ each\_with\_index ã¯  
ãã®ã¾ã¾ã«ã—ã¦ã¯ã©ã†ã§ã—ã‚‡ã†ã€‚

StringIO.new(“foo|bar|baz”).each("|").with\_index(1) { … }

ã€€ã¡ã‚‡ã£ã¨å‡ã£ãŸã“ã¨ã‚’ã—ãŸã‘ã‚Œã° Enumerator çµŒç”±ã§è¡Œã£ã¦ã­ã€  
ã¨ã„ã†ã‚¹ã‚¿ãƒ³ã‚¹ã¯æ‚ªãã¯ãªã„ã¨æ€ã„ã¾ã™ã€‚

---

<div class="post-metadata">

**Author:** ![Yusuke\_ENDOH](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/c89c15/32.png) [@Yusuke\_ENDOH](https://www.ruby-forum.com/u/Yusuke_ENDOH)\
**Post date:** [February 6, 2009, 4:51pm UTC](https://www.ruby-forum.com/t/feature-trunk-with-index-from/159538/6 "2009-02-06T16:51:32Z")

</div>

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

2009/2/6 Yukihiro M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> |e$B!!$3$3$O!“e(B with\_index e$B$K$@$10z?t$rDI2C$7$Fe(B each\_with\_index e$B$Oe(B  
> |e$B$=$N$^$^$K$7$F$O$I$&$G$7$g$&!#e(B  
> |  
> |StringIO.new(“foo|bar|baz”).each(”|").with\_index(1) { … }  
> |  
> |e$B!!$A$g$C$H6E$C$?$3$H$r$7$?$1$l$Pe(B Enumerator e$B7PM3$G9T$C$F$M!"e(B  
> |e$B$H$$$&%9%?%s%9$O0-$/$O$J$$$H;W$$$^$9!#e(B

e$B$J$k$[$I!\*e(B e$B46I~$7$^$7$?!#e(B

> each\_with\_indexe$B$OJ|CV!#e(BEnumerator#with\_indexe$B$NJ}$G\<jEv$F$9$ke(B  
> e$BJ}$K;?@.$7$^$9!#$,!"8=;~E@$G$O4J7i$Je(Bwith\_index(1)e$B$K$9$k$N$+!"e(B  
> e$B$h$jL@3N$Je(Bwith\_index\_from(1)e$B$K$9$k$N$+$O7hCG$G$-$^$;$s!#$I$Ce(B  
> e$B$A$,$h$$$G$7$g$&$M$(!#e(B

with\_index\_from e$B$O$d$`$J$/9M$($?$b$N$J$N$G!"e(Bwith\_index  
e$B$K$@$1e(B  
e$B0z?t$r;}$?$;$F$$$$$J$i$=$C$A$K0lI\<Ej$8$^$9!#e(B

with\_index e$B$@$10z?t$r;}$?$;$k%Q%C%A$G$9!#e(B

# Index: enumerator.c

— enumerator.c (revision 22101)  
+++ enumerator.c (working copy)  
@@ -406,32 +406,51 @@

/\*

- call-seq:

- 
  - e.with\_index {|(\*args), idx| … }

- 
  - e.with\_index(offset = 0) {|(\*args), idx| … }
  - e.with\_index
  - 
  - Iterates the given block for each element with an index, which

- 
  - start from 0. If no block is given, returns an enumerator.

- 
  - start from +offset+. If no block is given, returns an enumerator.
  - 

\*/  
static VALUE  
-enumerator\_with\_index(VALUE obj)  
+enumerator\_with\_index(int argc, VALUE \*argv, VALUE obj)  
{  
struct enumerator \*e;

- VALUE memo = 0;
- int argc = 0;
- VALUE \*argv = 0;

- VALUE memo;

- RETURN\_ENUMERATOR(obj, 0, 0);

- rb\_scan\_args(argc, argv, “01”, &memo);
- RETURN\_ENUMERATOR(obj, argc, argv);
- memo = NIL\_P(memo) ? 0 : (VALUE)NUM2LONG(memo);  
e = enumerator\_ptr(obj);  
if (e-\>args) {  
argc = RARRAY\_LEN(e-\>args);  
argv = RARRAY\_PTR(e-\>args);  
}
- else {
- argc = 0;
- argv = NULL;
- }  
return rb\_block\_call(e-\>obj, e-\>meth, argc, argv,  
enumerator\_with\_index\_i, (VALUE)&memo);  
}

+/\*

- 
  - call-seq:

- 
  - e.each\_with\_index {|(\*args), idx| … }

- 
  - e.each\_with\_index

- 
  - 

- 
  - Same as Enumeartor#with\_index, except each\_with\_index does not

- 
  - receive an offset argument.

- 
  - 

- \*/  
static VALUE  
+enumerator\_each\_with\_index(VALUE obj)  
+{
- return enumerator\_with\_index(0, NULL, obj);  
+}
- 

+static VALUE  
enumerator\_with\_object\_i(VALUE val, VALUE memo)  
{  
return rb\_yield\_values(2, val, memo);  
@@ -841,9 +860,9 @@  
rb\_define\_method(rb\_cEnumerator, “initialize”,  
enumerator\_initialize, -1);  
rb\_define\_method(rb\_cEnumerator, “initialize\_copy”,  
enumerator\_init\_copy, 1);  
rb\_define\_method(rb\_cEnumerator, “each”, enumerator\_each, 0);

- rb\_define\_method(rb\_cEnumerator, “each\_with\_index”,  
enumerator\_with\_index, 0);

- rb\_define\_method(rb\_cEnumerator, “each\_with\_index”,  
enumerator\_each\_with\_index, 0);  
rb\_define\_method(rb\_cEnumerator, “each\_with\_object”,  
enumerator\_with\_object, 1);

- rb\_define\_method(rb\_cEnumerator, “with\_index”,  
enumerator\_with\_index, 0);

- rb\_define\_method(rb\_cEnumerator, “with\_index”,  
enumerator\_with\_index, -1);  
rb\_define\_method(rb\_cEnumerator, “with\_object”,  
enumerator\_with\_object, 1);  
rb\_define\_method(rb\_cEnumerator, “next”, enumerator\_next, 0);  
rb\_define\_method(rb\_cEnumerator, “rewind”, enumerator\_rewind, 0);

---

<div class="post-metadata">

**Author:** ![Yusuke\_ENDOH](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/c89c15/32.png) [@Yusuke\_ENDOH](https://www.ruby-forum.com/u/Yusuke_ENDOH)\
**Post date:** [February 7, 2009, 8:04am UTC](https://www.ruby-forum.com/t/feature-trunk-with-index-from/159538/7 "2009-02-07T08:04:10Z")

</div>

At Sat, 7 Feb 2009 00:49:59 +0900,  
Yusuke ENDOH wrote:

> 2009/2/6 Yukihiro M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):  
> (snip)
> 
> > each\_with\_indexã¯æ”¾ç½®ã€‚Enumerator#with\_indexã®æ–¹ã§æ‰‹å½“ã¦ã™ã‚‹  
> > æ–¹ã«è³›æˆã—ã¾ã™ã€‚ãŒã€ç¾æ™‚ç‚¹ã§ã¯ç°¡æ½”ãªwith\_index(1)ã«ã™ã‚‹ã®ã‹ã€  
> > ã‚ˆã‚Šæ˜Žç¢ºãªwith\_index\_from(1)ã«ã™ã‚‹ã®ã‹ã¯æ±ºæ–­ã§ãã¾ã›ã‚“ã€‚ã©ã£  
> > ã¡ãŒã‚ˆã„ã§ã—ã‚‡ã†ã­ãˆã€‚
> 
> with\_index\_from ã¯ã‚„ã‚€ãªãè€ƒãˆãŸã‚‚ã®ãªã®ã§ã€with\_index ã«ã ã‘  
> å¼•æ•°ã‚’æŒãŸã›ã¦ã„ã„ãªã‚‰ãã£ã¡ã«ä¸€ç¥¨æŠ•ã˜ã¾ã™ã€‚

ã€€ã§ã¯ã“ã‚Œã§è¡Œãã¾ã—ã‚‡ã†ã‹ã€‚

> - Iterates the given block for each element with an index, which
> 
> - 
> - start from 0. If no block is given, returns an enumerator.
> 
> - 
> - start from +offset+. If no block is given, returns an enumerator.
> -

ã€€ã“ã‚Œã¯å…ƒã®grammoãªã‚“ã§ã™ãŒã€ s/start/starts/ ã¨ç›´ã—ã¦ãã ã•ã„ã€‚

ã€€ã“ã‚Œã¨ã¯åˆ¥ä»¶ã§ã™ãŒã€ yield args, i ã§ã¯ãªã yield \*args, i ã®  
æ–¹ãŒã„ã„ã¨ã„ã†æ„è¦‹ãŒã‚ã£ãŸæ°—ãŒã—ã¾ã™ãŒã©ã†ãªã‚“ã§ã—ã‚‡ã†ã­ã€ã¨ã„ã†  
ã¨ã“ã‚ã§ [1,2,3].each.with\_index.with\_index {|x| … } ãŒã†ã¾ã  
è¡Œã‹ãªã„ã“ã¨ã«æ°—ãŒã¤ã„ãŸâ€¦ã€‚

---

<div class="post-metadata">

**Author:** ![Yusuke\_ENDOH](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/c89c15/32.png) [@Yusuke\_ENDOH](https://www.ruby-forum.com/u/Yusuke_ENDOH)\
**Post date:** [February 8, 2009, 3:48pm UTC](https://www.ruby-forum.com/t/feature-trunk-with-index-from/159538/8 "2009-02-08T15:48:16Z")

</div>

e$B%A%1%C%He(B #1112 e$B$,99?7$5$l$^$7$?!#e(B (by Yusuke E.)

e$B%9%F!\<%?%9e(B Opene$B$+$ie(BClosede$B$KJQ99e(B  
e$B?JD=e(B % 0e$B$+$ie(B100e$B$KJQ99e(B

## Applied in changeset r22134.

[http://redmine.ruby-lang.org/issues/show/1112](http://redmine.ruby-lang.org/issues/show/1112)

---

<div class="post-metadata">

**Author:** ![Yusuke\_ENDOH](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/c89c15/32.png) [@Yusuke\_ENDOH](https://www.ruby-forum.com/u/Yusuke_ENDOH)\
**Post date:** [February 12, 2009, 9:01am UTC](https://www.ruby-forum.com/t/feature-trunk-with-index-from/159538/9 "2009-02-12T09:01:05Z")

</div>

e$B%A%1%C%He(B #1119 e$B$,99?7$5$l$^$7$?!#e(B (by Nobuyoshi N.)

e$B%9%F!\<%?%9e(B Opene$B$+$ie(BClosede$B$KJQ99e(B

## separated from #1112 unintentionally.

[http://redmine.ruby-lang.org/issues/show/1119](http://redmine.ruby-lang.org/issues/show/1119)
