From: Gavin Sinclair Date: 2004-09-09T13:17:03+09:00 Subject: Re: [RCR] Unified type conversion framework > Florian Gross wrote: >> Paul Brannan wrote: >> >>> I think you mean Hash[*anArray]. IMO, It's not totally unintuitive, >>> but it's not consistent with other conversions. >> >> >> Actually converting an assoc array to a Hash is done via >> Hash[*array.flatten]. I think that that is pretty low level. I'd >> prefer something like Hash.from_assoc() > > At work we have Array#to_h in a library, it's really useful for things > like: > > db.select_all(...).map {|foo,bar| [foo,bar]}.to_h > > Sam This is my approach (very similar) and I love it: require 'extensions/all' db.select_all(...).build_hash { |foo, bar| [foo,bar] } Gavin