From: Sebastian Hungerecker Date: 2007-11-23T01:03:32+09:00 Subject: Re: Ruby hashes Alvaro Perez wrote: > Example: An array of objects Teacher, each with his name and belonging > school. After iterating though its elements, we want an output of the > type, "school_name_A" => "teacher_name_A", "school_name_B" => > ["teacher_name_B", "teacher_name_C"]. hash = Hash.new {|h,k| h[k] = []} teachers.each do |teacher| hash[teacher.school] << teacher.name end HTH, Sebastian -- NP: Explosions in the Sky - Snow And Lights Jabber: sepp2k@jabber.org ICQ: 205544826