mardi 20 août 2019

sort ruby hash by specific key

I have a ruby hash like this

 {"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"}

How do I sort this by name? I tried

 categories.sort_by {|_key, value, _key1, value1| value1}

But that did not work

Aucun commentaire:

Enregistrer un commentaire