From: botp Date: 2010-05-31T20:21:16+09:00 Subject: Re: enumerator problem in 1.9.1 On Mon, May 31, 2010 at 4:34 PM, Robert Klemme wrote: > 2010/5/31 botp : >> On Mon, May 31, 2010 at 9:04 AM, Bug Free wrote: >>> The following line: >>> >>>    [5, 7].each_with_index.each_cons(2) {|v| p v } >>> >>> prints [5, 7] but I'm expecting [[5, 0], [7, 1]]. >> >> you'll have specify the index, eg, >> >>>>  [5, 7].map.with_index{|v,i| [v,i]} >> => [[5, 0], [7, 1]] > > That's not the proper replacement with map.  Rather you'd do: > > irb(main):009:0> [5, 7].each_with_index.map {|v| v } > => [5, 7] > irb(main):010:0> [5, 7].each_with_index.map {|*v| v } > => [[5, 0], [7, 1]] brain dead here. can you enlighten me on what is "not proper" ? :) ie why is each_with_index.map preferable over map.with_index ? kind regards -botp