From: Ryan Leavengood Date: 2005-06-26T23:54:15+09:00 Subject: Re: grouping/sorting [newbie question] bdarcus@gmail.com wrote: > > However, while I figured out how to sort the list correctly, I don't > really understand how to do the grouping. Could someone please explain? Inject is your friend: require 'yaml' films = YAML::load(File.open("film.yaml")) grouped_comments = films.inject({}) do |grouped, film| (grouped[film['title']] ||= []) << film['comments'] grouped end grouped_comments.keys.sort.each do |title| puts "Comments for #{title}:" grouped_comments[title].each do |comment| puts "\t#{comment}" end end Ryan