Top > Ruby [2.2.2] > ハッシュを並び替え
hash = [[1, 39], [3, 53], [2, 46], [4, 43], [6, 32], [5, 32]]
p hash.to_a.sort { |a, b| (b[1] <=> a[1]) * 2 + (a[0] <=> b[0]) }
# [[3, 53], [2, 46], [4, 43], [1, 39], [5, 32], [6, 32]]
p hash.to_a.sort { |b, a| (b[1] <=> a[1]) * 2 + (a[0] <=> b[0]) }
# [[6, 32], [5, 32], [1, 39], [4, 43], [2, 46], [3, 53]]