Forum: Ruby-core Map a hash directly to a hash

3df767279ce7d81db0a5bb30f5136863?d=identicon&s=25 Matthew Kerwin (mattyk)
on 2014-03-13 14:30
(Received via mailing list)
Issue #9635 has been updated by Matthew Kerwin.


 At the risk of being terse, https://bugs.ruby-lang.org/issues/7793

----------------------------------------
Feature #9635: Map a hash directly to a hash
https://bugs.ruby-lang.org/issues/9635#change-45759

* Author: Andrey Mikhaylov
* Status: Open
* Priority: Normal
* Assignee:
* Category:
* Target version:
----------------------------------------
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' }
~~~
This topic is locked and can not be replied to.