Method: Dry::Transformer::HashTransformations.map_value

Defined in:
lib/dry/transformer/hash_transformations.rb

.map_value(hash, key, fn) ⇒ Hash

Map a key in a hash with the provided transformation function

Examples:

Dry::Transformer(:map_value, 'name', -> s { s.upcase })['name' => 'jane']
# => {"name" => "JANE"}

Parameters:

  • (Hash)

Returns:

  • (Hash)


230
231
232
# File 'lib/dry/transformer/hash_transformations.rb', line 230

def self.map_value(hash, key, fn)
  hash.merge(key => fn[hash[key]])
end