On Oct 8, 8:00 ¨Βν¬ Πετε ΘοδησοΌπθοδη®®®ΐμωςισ®γονΎ χςοτεΊ > 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. > > Thanks for any pointers, > Pete Hash[ * people_array.map{|x| [ x.name, x ] }.flatten ] ==>{"dave" => #<struct Person name="dave", age=14, city="NYC">, "jane" => #<struct Person name="jane", age=6, city="LDN">, "bob" => #<struct Person name="bob", age=12, city="SFO">}