我有一个像这样的红宝石哈希
{"id"=>62, "name"=>"Wine and Spirits"}
{"id"=>63, "name"=>"Tobacco"}
{"id"=>64, "name"=>"Printing"}
{"id"=>65, "name"=>"Information Services"}
{"id"=>66, "name"=>"Business Supplies and Equipment"}
如何按名称对它进行排序?我尝试过
categories.sort_by {|_key, value, _key1, value1| value1}
但这没用
答案 0 :(得分:0)
假设您要对哈希数组进行排序:
def sort_by_name(hashes)
hashes.sort_by { |h| h["name"] }
end