Method: MapJune 14, 2015 · 2 Minute Read
I'm quite new to the realm of Ruby. Don't get me wrong, I'm a hughe fan. There are just a few things (many, many things) that I don't quite understand yet. I'm going to throw some concept descriptions down below, but just so you know where I'm going with this - this post is about the Ruby 'map' method. It's a super-simple, super-useful method. See below for descriptions and examples.
Alias - Methods with different names that operate identically. Often included out of consideration for programmers that use multiple languages (
collect are aliases).
Module - Modules are a way of grouping together methods, classes, and constants - like a package! Collection of code that someone has written that you can now use. Reuseable code.
Mixin - ??? (like I said above, I don't know everything, yet)
The Enumerable Module (the map method belongs to this module) - traversal (iterative), can do serching, sorting, and comparisons. Really Useful Stuff.
The Map Method - Takes an array, performs a specified operation or operations on each element, returns a new array with new elements.
Destuctive vs. Nondestructive Methods -
map is a nondestructive method,
map! is a destructive method. The only difference between the two is that
map! will change (destroy) the array you give it, and
map will not.
map will create and return a new Array instance with your new values.
Hopefully that made sense. Can anyone explain what a mixin is? (Edit - Read this post I made about Modules, Classes, Namespace, and Mixins).