ruby 中数组多层排序
[1] pry(main)> aa = [[1],[2],[3],[0],[1,2,3],[1,0,1],[0,1,2],[1,1,5],[1,1,3]]
=> [[1], [2], [3], [0], [1, 2, 3], [1, 0, 1], [0, 1, 2], [1, 1, 5], [1, 1, 3]]
[2] pry(main)> aa.sort_by {|a| [a.size, a[0], a[2], a[1]]}
=> [[0], [1], [2], [3], [0, 1, 2], [1, 0, 1], [1, 1, 3], [1, 2, 3], [1, 1, 5]]
[3] pry(main)> aa.sort {|a, b| [a.size, a[0], a[2], a[1]] <=> [b.size, b[0], b[2], b[1]]}
=> [[0], [1], [2], [3], [0, 1, 2], [1, 0, 1], [1, 1, 3], [1, 2, 3], [1, 1, 5]]
[4] pry(main)> aa.sort {|a, b| [a.size, a[0], b[2], a[1]] <=> [b.size, b[0], a[2], b[1]]}
=> [[0], [1], [2], [3], [0, 1, 2], [1, 1, 5], [1, 1, 3], [1, 2, 3], [1, 0, 1]]