From: Peter Vandenabeele Date: 2010-12-26T17:47:19+09:00 Subject: Re: array index inside map function Siddharth Venkatesan wrote in post #970728: > Hi all, > > how can i access the index of the element inside the map argument block? > > "101010,234,876".split(",").map {|c| get_something(c)} > > this works. But the problem is i need to apply the get_something on only > the > second and third element of the array. How can I check the index of the > element inside the map block? There is each_with_index, but that has the "each" functionality and not the "map"/"collect" functionality. That would be (not tested): result = [] "101010,234,876".split(",").each_with_index {|c, i| result << do_something(c,i)} HTH, Peter -- Posted via http://www.ruby-forum.com/.