Enumerables is a Ruby Module that contains a collection of abilities to do search and sort on a block or array. You can do things like group by, find, reject and sort among other things. Today we’re going to take a look at Enumerable#map
The map method takes an enumerable object and a block, and runs the block for each element, outputting each returned value from the block.
You can also do a map! (with the exclamation mark) and it will become destructive, replacing the array that was used with the map! function.
When am I ever going to need to use map? Say you want to convert an array of number grades into an array of letter grades. We can use map to do that.
You might think, why use map instead of each? Well each is also part of enumerables, but it wont return an array with your results
About the Author
Hello, I'm Ronald Ishak, a tech entrepreneur, blogger, father, developer from Jakarta Indonesia. I use this blog to document what I learn. If it helps you, please consider leaving a comment or sharing it!