The difference between Enumerable#each
and Enumerable#map
is whether it returns the receiver or the mapped result. Getting back to the receiver is
The difference between map
and each
is more important than whether one returns a new array and the other doesn't. The important difference is in how they communicate your intent.
When you use each
, your code says "I'm doing something for each element." When you use map
, your code says "I'm creating a new array by transforming each element."
So while you could use map
in place of each
, performance notwithstanding, the code would now be lying about its intent to anyone reading it.