concept new array in category ruby

appears as: new array, The new array
The Well-Grounded Rubyist, Third Edition

This is an excerpt from Manning's book The Well-Grounded Rubyist, Third Edition.

Like each, map walks through an array one element at a time and yields each element to the code block. The difference between each and map lies in the return value: each returns its receiver, but map returns a new array. The new array is always the same size as the original array; but instead of the original elements, the new array contains the accumulated return values of the code block from the iterations.

In this example, the new array has a size of 3. This number can also be passed to the block as an iterator 1. The code inside the block #1, executed three times, produces the values 10, 20, and 30—and those are the initial values in the array 2.