[#78633] ruby/spec needs help from CRuby committers — Benoit Daloze <eregontp@...>
Currently, ruby/spec is maintained mostly by individuals and enjoys the
13 messages
2016/12/13
[#78963] Re: ruby/spec needs help from CRuby committers
— Urabe Shyouhei <shyouhei@...>
2017/01/04
I did ask attendees of last developer meeting to join this
[#78642] Re: ruby/spec needs help from CRuby committers
— Eric Wong <normalperson@...>
2016/12/14
Benoit Daloze <eregontp@gmail.com> wrote:
[ruby-core:78524] [Ruby trunk Feature#10208][Feedback] Passing block to Enumerable#to_h
From:
shyouhei@...
Date:
2016-12-07 04:28:41 UTC
List:
ruby-core #78524
Issue #10208 has been updated by Shyouhei Urabe.
Status changed from Open to Feedback
FYI if there are people who need this functionality: so far we have not found an appropriately sounding name of this method. It should be a method of Enumerable (not only Hash), that takes a block, and returns a Hash.
----------------------------------------
Feature #10208: Passing block to Enumerable#to_h
https://bugs.ruby-lang.org/issues/10208#change-61909
* Author: Yutaka HARA
* Status: Feedback
* Priority: Normal
* Assignee:
----------------------------------------
Now that we can convert 'a list of [key, value] pairs' into a hash with Enumerable#to_h,
how about make it take a block to specify 'how to convert each element into a [key, value] pair'?
Example:
~~~
# Convert users into an {id => name} hash
users.map{|u| [u.id, u.name]}.to_h
↓
# Convert users into an {id => name} hash
users.to_h{|u| [u.id, u.name]}
~~~
This could also be a solution for these feature requests:
* Feature #6669 A method like Hash#map but returns hash
hsh.apply{|k, v| [k.to_s, v]}
== hsh.to_h{|k, v| [k.to_s, v]}
* Feature #7793 New methods on Hash
Feature #9970 Add `Hash#map_keys` and `Hash#map_values`
hsh.map_k(&:to_s)
== hsh.to_h{|k, v| [k.to_s, v]}
hsh.map_v(&:to_i)
== hsh.to_h{|k, v| [k, v.to_i]}
hsh.map_kv(&block)
== hsh.to_h(&block)
--
https://bugs.ruby-lang.org/
Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>