From: Logan Capaldo Date: 2006-09-05T22:41:30+09:00 Subject: Re: Enum On Sep 5, 2006, at 9:06 AM, Ohad Lutzky wrote: > Hmm, which reminds me. Why don't we get one of these with ruby? > > module Enumerable > def collect_with_index > arr = [] > self.each_with_index do |a,i| > arr << yield(a,i) > end > arr > end > end > We do: require 'enumerator' ['a', 'b', 'c'].to_enum(:each_with_index).map { |value, index| { index => value } } #=> [{0=>'a'}, {1=>'b'}, {2=>'c'}] > -- > Posted via http://www.ruby-forum.com/. >