Module: Enumerable

Defined in:
lib/rarff.rb

Instance Method Summary collapse

Instance Method Details

#map_with_indexObject

This map_with_index hack allows access to the index of each item as the map iterates. TODO: Is there a better way?



27
28
29
30
31
32
33
34
# File 'lib/rarff.rb', line 27

def map_with_index
  # Ugly, but I need the yield to be the last statement in the map.
  i = -1 
  return map { |item|
    i += 1
    yield item, i
  }
end