From: Aaron Patterson Date: 2012-10-30T08:18:06+09:00 Subject: [ruby-core:48553] Re: [ruby-trunk - Feature #7241][Open] Enumerable#to_h proposal On Tue, Oct 30, 2012 at 07:23:29AM +0900, nathan.f77 (Nathan Broadbent) wrote: > > Issue #7241 has been reported by nathan.f77 (Nathan Broadbent). > > ---------------------------------------- > Feature #7241: Enumerable#to_h proposal > https://bugs.ruby-lang.org/issues/7241 > > Author: nathan.f77 (Nathan Broadbent) > Status: Open > Priority: Normal > Assignee: > Category: core > Target version: > > > I often use the `inject` method to build a hash, but I always find it annoying when I need to return the hash at the end of the block. > This means that I often write code like: > > [1,2,3,4,5].inject({}) {|hash, el| hash[el] = el * 2; hash } 1.9.3p194 :001 > [1,2,3,4].each_with_object({}) { |x,o| o[x] = x ** 2 } => {1=>1, 2=>4, 3=>9, 4=>16} 1.9.3p194 :002 > -- Aaron Patterson http://tenderlovemaking.com/