From: hemant Date: 2007-07-16T20:46:36+09:00 Subject: Re: clean nice way (hash) On 7/16/07, SonOfLilit wrote: > On 7/16/07, hemant wrote: > > On 7/16/07, Shai Rosenfeld wrote: > > > hi, > > > was wondering what the prettiest way to do the below would be: > > > > > > i got a hash > > > > > > { '1' => 'some', '4' => 'thing', '6' => 'good' } > > > > > > and i want to turn it into > > > > > > { '1' => {'name' => 'some'}, '4' => {'name' => 'thing'}, '6' => > > > {'name'=>'good'} } > > > > Dunno, I can think of a couple of ways: > > > > a.each {|key,value| a[key] = {'name' => value}} > > Are you allowed to do this? Why not? Seem to work here. > > > or > > > > a.inject({}) {|mem,(key,value)| mem[key] = {'name' => value}; mem } > > Wow, thanks for showing me a new idea. > > > Aur > > -- Let them talk of their oriental summer climes of everlasting conservatories; give me the privilege of making my own summer with my own coals. http://blog.gnufied.org