map

.map() { |element| ... }

Yields over each element in the array into the attached block. A new array is returned with each element replaced with the return value of the block.

Note that this returns a copy of the array, it does not mutate the original.

ns = [ 1, 2, 3 ]

// doubles each value
doubleNs = ns.map() do |n|
    return n*2
end

See also

fill