I would have thought it would be easy, and searched for it is quite difficult, but it seems it cannot make it work.
I have the following hash:
@friends = [{"name"=>"John Smith", "id"=>"12345"}, {"name"=>"Jane Doe", "id"=>"23456"}, {"name"=>"Samuel Jackson", "id"=>"34567"}, {"name"=>"Kate Upton", "id"=>"45678"}]
I am trying to sort it alphabetically by name.
Now I am doing this:
@friends.sort{|a,b| a[0]<=>b[0]}
However, it simply displays the full results in alphabetical order.
source
share