Ruby do/end vs braces
That has to do with the difference in associativity of the {
character and the do
keyword.
In the first case, the block is interpreted as a block argument to the map
function. The result of the map function is the argument to the p
function.
In the second case, the block is interpreted as a block argument to the p
function, while the a.map
is interpreted as the first argument to the p
function. Since a.map
evaluates to a
, this prints the original array. The block is effectively ignored in this case.