On Jul 16, 2007, at 12:10 PM, Robert Klemme wrote:

> On 16.07.2007 17:03, James Edward Gray II wrote:
>> On Jul 16, 2007, at 9:36 AM, Robert Klemme wrote:
>>> 2007/7/16, Chris Carter <cdcarter / gmail.com>:
>>>> On 7/16/07, James Edward Gray II <james / grayproductions.net> wrote:
>>>> > On Jul 16, 2007, at 5:58 AM, hemant wrote:
>>>> >
>>>> > > a.inject({}) {|mem,(key,value)| mem[key] = {'name' =>  
>>>> value}; mem }
>>>> >
>>>> > I would write that as:
>>>> >
>>>> >    a.inject(Hash.new) { |h, (k, v)| h.merge(k => v) }
>>>> >
>>>> > James Edward Gray II
>>>> >
>>>> >
>>>>
>>>> But that doesn't yield what he wanted... You could do
>>>> a.inject(Hash.new){|h,(k,v)| h.merge(k => { 'name' => value})}
>>>
>>> Still it's inefficient because of all the small Hashes that are  
>>> thrown
>>> away immediately. The solution provided by hemant is better although
>>> not as elegant.
>> If that bothers you, change merge() to merge!().
>
> ... which doesn't help because it does not avoid all those one pair  
> hashes. :-)

I did eliminate some Hashes, those created for each iteration inject 
(), so I feel it's wrong to say it didn't help.  You are right about  
the parameter Hashes though.

I do feel nitpicking something like this is squarely in the domain of  
premature optimization though.  It's GC's job to lose sleep over the  
objects I create, not mine.  I don't need to get involved until it  
looks like GC is getting behind.  Those are my feelings on the matter.

James Edward Gray II