From: Russell Fulton Date: 2006-08-15T08:17:56+09:00 Subject: Re: Consecutive sort on Array of Hashes Laurent Colloud wrote: > > puts "Team, Pts, W, D, L" > myArray = myArray.sort { |a,b| b[:d] <=> a[:d] > }.sort { |a,b| b[:w] <=> a[:w] > }.sort { |a,b| b[:pts] <=> a[:pts] > }.each do |row| > puts "#{row[:team_id]}, #{row[:pts]}, #{row[:w]}, #{row[:d]}, > #{row[:l]}" > end > I suspect the problem is that sort does not keep the order of equal keys -- this is standard depending on which algorithim used. you need to do one sort with a more complex comparison routine: {|a,b| if b[:pts] == a[:pts] then if b[:w] == a[:w] then b[:d] <=> a[:d] else b[:w] <=> a[:w] end b[:pts] <=> a[:pts] end } -- Posted via http://www.ruby-forum.com/.