Actions
Feature #9970
closedAdd `Hash#map_keys` and `Hash#map_values`
Description
These methods simplify two common patterns when working with hashes, and transforming the data.
Without map_keys
:
Hash[{ a: 1, b: 2 }.map { |key, value| [key.to_s, value] }]
With map_keys
:
{ a: 1, b: 2 }.map_keys(&:to_s)
Without map_values
:
Hash[{ a: '1', b: '2' }.map { |key, value| [key, value.to_i] }]
With map_values
:
{ a: '1', b: '2' }.map_values(&:to_i)
The patch, with tests, is attached.
Files
Actions
Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0