From: Nathan Broadbent Date: 2012-11-08T05:00:25+09:00 Subject: [ruby-core:49064] [ruby-trunk - Feature #7297][Open] map_to alias for each_with_object --e89a8f83a4d93430c904cded2bde Content-Type: text/plain; charset=ISO-8859-1 > So consider Enumerable#associate which builds a mapping by *associating* keys with values I like Enumerable#associate. It would cover many of the cases where each_with_object({}) is currently used. However, I think '[[1,2],[3,4]].to_h' would be better for when an Array is already in the 'associated' form. See #7292 for that discussion: https://bugs.ruby-lang.org/issues/7292 . If the #to_h method was also available, then #associate could require a block, and it would be the inverse of Active Support's 'index_by' method (it would yields values instead of keys): http://api.rubyonrails.org/classes/Enumerable.html#method-i-index_by I'm still wondering if there should be a method that allows you to return both key and value, but 'map {|e| [e * 2, e ** 2] }.to_h' would probably be sufficient. (sorry for bringing #7292 into the discussion, but I feel like it's a related issue.) --e89a8f83a4d93430c904cded2bde Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable >=A0So consider Enumerable#associate which builds a mapping by *as= sociating* keys with values

I = like Enumerable#associate. It would cover many of the cases where each_with= _object({}) is currently used.

However, I think '[[1,2],[3,4]].to_h&#= 39; would be better for when an Array is already in the 'associated'= ; form. See #7292 for that discussion:=A0https://bugs.ruby-lang.org/issues/7292.=

If the #to_h method was also available, the= n #associate could require a block, and it would be=A0the inverse of Active Support's 'index_by&#= 39; method (it would yields values instead of keys):=A0= http://api.rubyonrails.org/classes/Enumerable.html#method-i-index_by=

I'm still wondering if there should be = a method that allows you to return both key and value, but=A0=A0'map {|e| = [e * 2, e ** 2] }.to_h' would probably be sufficient.=A0<= /div>

(sorry for = bringing #7292 into the discussion, but I feel like it's a related issu= e.)

--e89a8f83a4d93430c904cded2bde--