I am confused with the working of a.map and a.map! on the array
collection.
The documentation is quite clear:
$ ri Array#map
…
…
Invokes the given block once for each element of self.
Creates a new array containing the values returned by the block.
…
…
$ ri Array#map!
…
…
Invokes the given block once for each element of self, replacing the
element
with the value returned by the block.
…
…
Methods ending with ! usually modify the original object.
You’ll find this symbol on quite a few methods in Ruby, in general there
will only be a method with “!” (modify the object in place) if there’s
also one which returns a new object without changing the original. Look
up “Ruby Bang Methods” for more info.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.