Actions
Feature #10208
closedPassing block to Enumerable#to_h
Feature #10208:
Passing block to Enumerable#to_h
Status:
Closed
Assignee:
-
Target version:
-
Description
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:
Actions