P
Pete Hodgson
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
Given:
Person = Struct.new
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