2011/6/22 Phillip Gawlowski <cmdjackryan / googlemail.com>: > I suspect you want to output this hash ordered by priority, correct? Not exactly. Well, not at all in fact :) Being more explicit, I use em-udns library ang perform a DNS SRV query for a domain, and get an array of one1 or more EventMachine::Udns::RR_SRV instances. Each object has a priority value (and also weight, but I don't care it now): https://github.com/ibc/em-udns Note that priorities don't need to be correlated, this is, there could be 4 entries with these priorities: - 1 => A - 10 => B - 1 => C - 3 => D I just want to get an ordered hash in which: - The key is the priority (in the given example there would be 3 entries: 1, 3 and 10). - The value is an array with all the valus with such priority. So, what I want to get is: { 1 => [A, C], 3 => [D], 10 => [B] } What I do know is: - Get the DNS result array: srvs = [ object1, object2, object3, object4 ] - Order the array based on Object#priority. srvs.sort_by{|e| e.priority} - Construct the hash: ordered_hash = {} srvs.sort_by{|e| e.priority}.each do |srv| ordered_hash[srv.priority| ||= [] ordered_hash[srv.priority| << srv.value end It just works. Initially I tryed a different approach so my original question was a bit different. -- IƱaki Baz Castillo <ibc / aliax.net>