From: Jason Roelofs Date: 2008-01-04T09:17:41+09:00 Subject: Re: Troubles with blocks ------=_Part_35970_17045382.1199405867706 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline On Jan 3, 2008 7:13 PM, MenTaLguY wrote: > On Fri, 4 Jan 2008 08:49:54 +0900, Holden Holden > wrote: > > Python: > > > > list(enumerate(['a','b','c'])) > > => [(0, 'a'), (1, 'b'), (2, 'c')] > > > > Ruby: > > > > t = []; ['a','b','c'].each_with_index { |*x| t << x }; t > > => [["a", 0], ["b", 1], ["c", 2]] > > > > Which is a very ugly solution. How could I do this on Ruby without a > > temporal variable? > > Try this (you will need to require 'enumerator'): > > ['a','b','c'].enum_with_index.to_a > > -mental > > Ah, that's where enum_with_index is. I was wondering why it wasn't working for me. Jason ------=_Part_35970_17045382.1199405867706--