Method: Enumerable#map_with_index

Defined in:
lib/webget_ruby_ramp/enumerable.rb

#map_with_indexObject

Map each item and its index => a new output

cf. Enumerable#map, Enumerable#each_with_index

Example

strings = ["a", "b", "c"]
strings.map_with_index{|string,index| "#{string}#{index}"}
 => ["a0, "b1", "c3"]


191
192
193
194
# File 'lib/webget_ruby_ramp/enumerable.rb', line 191

def map_with_index
  index=-1
  map{|item| index+=1; yield(item,index)}
end