我想通过两个不同的条件对该数组进行排序。
首先,我想按类型对数组进行排序:类型可以是 (1,2,3,4),我想按 4 - 1 - 2 - 3 的顺序对它们进行排序。
然后,在每种不同的类型中,我想按百分比降序对它们进行排序。
因此,排序后的数组将如下所示:
[
<OpenStruct percent=70, type=4>,
<OpenStruct percent=60, type=4>,
<OpenStruct percent=50, type=4>,
<OpenStruct percent=73, type=1>,
<OpenStruct percent=64, type=1>,
<OpenStruct percent=74, type=2>
]ect
我怎样才能完成这种工作?目前我只能按类型降序排序。
array = array.sort_by {|r| r.type }