Each vs. Map vs. Collect
The Ruby enumerable methods are incredibly useful so I thought I'd take a look at three very similar methods and discuss how they differ.
Each is your basic iteration method and is called on collections of elements. It accepts a block which will be run on each element in the collection. While it runs on each element, the return value is discarded.
Map is a variation of Each. It also accepts a block which will be run on each element in the collection. The difference being that Map returns a new array with the results of running the block.
Collect is an alias for Map and works exactly the same.
Let's run these methods on the same array to illustrate the differences.