This blog is part of our Ruby 2.4 series.
It is a common use case
the values of a hash.
We can transform the values of a hash destructively
(i.e. modify the original hash with new values)
(i.e. return a new hash instead of modifying the original hash).
Prior to Ruby 2.4,
we need to use
to transform the values of a hash.
transform_values and transform_values! from Active Support
has already implemented handy methods
Hash#transform_values and Hash#transform_values!
to transform hash values.
Ruby 2.4 has also implemented
Hash#map_v and Hash#map_v!
and then renamed to Hash#transform_values and Hash#transform_values!
for the same purpose.