<分区>
让 o1, o2, o3, o4
activerecord 对象与
o1.kind = "att2"
o2.kind = "att3"
o3.kind = "att4"
o4.kind = "att1"
让 a = [o1, o2, o3, o4]
令 b = ['att1', 'att3', 'att4', 'att2']
我需要对 a
和 b
进行排序,以便 a
中的新顺序变为:
a = [o4, o2, o3, o1]
我试过了
a.sort_by do |element|
b.index(element)
end
但是如何按种类排序呢?