eachMapping

.eachMapping() { |index, element| ... }

Iterates over each item is array, and yields the index and element into the attached block. This is done in order.

ns = [ 1, 2, 3, 4 ]

// doubles every other number
ns.eachMapping() do |i, number|
    if i % 2 == 1
        ns[i] = number*2
    end
end

See also

each - eachMapping