Project

General

Profile

Actions

Feature #9635

open

Map a hash directly to a hash

Added by lolmaus (Andrey Mikhaylov) over 7 years ago. Updated over 7 years ago.

Status:
Open
Priority:
Normal
Assignee:
-
Target version:
-
[ruby-core:61462]

Description

There should be a way to directly map a hash to a hash.

The current way to do it is not very graceful:

{foo: 'foo', bar: 'bar'}.map { |key, value| [key.upcase, value.reverse] }.to_h     # => { :FOO => 'oof', :BAR => 'rab' }

I think there should be a simpler and more natural way to do that. Something like this:

{foo: 'foo', bar: 'bar'}.hashy_map { |key, value| key.upcase => value.reverse }    # => { :FOO => 'oof', :BAR => 'rab' }

Related issues

Related to Ruby master - Feature #12512: Import Hash#transform_values and its destructive version from ActiveSupportClosedmatz (Yukihiro Matsumoto)Actions
Actions

Also available in: Atom PDF