Thanks! Sorry, I didn't know about each_with_object.

Do you think it would still be worth shortening
`each_with_object(Hash.new([])) { ... }` to `to_h([]) { ... }`, and are any
of the other cases worth supporting?


Best,
Nathan

On Tue, Oct 30, 2012 at 12:18 PM, Aaron Patterson
<tenderlove / ruby-lang.org>wrote:

> 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/
>
>