From: Phrogz Date: 2007-07-21T04:44:59+09:00 Subject: Re: Array : each_with_index On Jul 19, 3:06 am, Pe�a, Botp wrote: > 1 puts "---scheme 1---" > 2 r = ['KLP','OGN'] > 3 msg =< 4 #{puts "Found #{r.length} orders"} > 5 #{r.map.each_with_index{|v,i| puts "(#{i+1}) #{v}\n" }} > 6 MSG > 7 msg > 8 > 9 puts "---scheme 2---" > 10 r = ['KLP','OGN'] > 11 < 12 #{puts "Found #{r.length} orders"} > 13 #{r.map.each_with_index{|v,i| puts "(#{i+1}) #{v}\n" }} > 14 MSG > 15 > 16 puts "---scheme 3---" > 17 r = ['KLP','OGN'] > 18 puts "Found #{r.length} orders" > 19 r.each_with_index{|v,i| puts "(#{i+1}) #{v}\n" } One other variation which looks a little closer to what the OP wanted: module Enumerable def map_with_index idx = -1 map{ |v| yield v,idx+=1 } end end puts "---scheme 4---" r = ['KLP','OGN'] msg =<