From: Logan Capaldo Date: 2006-10-30T01:40:46+09:00 Subject: Re: Define a hash using %q? On Sun, Oct 29, 2006 at 03:56:34PM +0900, Joel VanderWerf wrote: > Logan Capaldo wrote: > ... > >Alternative decandence: > >class Array > > def to_hsh > > require 'enumerator' > > to_enum(:each_slice, 2).to_a.inject({}) { |h, (k, v)| h.update(k=>v) } > > Injecting hash may be your idea of decadence, but it's too much hard > work for me. I just splat myself: > > def to_hsh > Hash[*self] > See when I usually write this code it's because it's coming out of a #zip, and then you must flatten it to use the splat, and flatten is too greedy if you nested arrays. So it was force of habit. In this case you are absolutely correct. > > end > >end > > -- > vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407