From: Trans Date: 2008-10-09T11:54:25+09:00 Subject: Re: Filling a hash from an enumerable On Oct 8, 9:00 pm, Pete Hodgson wrote: > Hi folks, > > Given: > > Person = Struct.new(:name,:age,:city) > people_array = [ >     Person.new('bob',12,'SFO'), >     Person.new('dave',14,'NYC'), >     Person.new('jane',6,'LDN') ] > > people_map = {} > people_array.each{ |p| people_map[p.name] = p } > > Is there a cleaner way to build people_map? I'm thinking there might be > something like: > > people_map = people_array.to_map{ |x| x.name } > > in the standard library somewhere that I don't know of. Facets has #graph / #mash. require 'facets' people_array.graph{ |p| [p.name, p] } # or people_array.mash{ |p| [p.name, p] } T.