Module: Enumerable

Defined in:
lib/metamorpher/support/map_at.rb

Instance Method Summary collapse

Instance Method Details

#map_at(index, &block) ⇒ Object

Returns a new array with the element at index replaced by the result of running block on that element.


4
5
6
7
# File 'lib/metamorpher/support/map_at.rb', line 4

def map_at(index, &block)
  fail IndexError if index < 0 || index >= size
  each_with_index.map { |e, i| i == index ? block.call(e) : e }
end