Skip to content

Instantly share code, notes, and snippets.

@aereal
Created Jun 4, 2010
Embed
What would you like to do?
hash = {:a => 40, :b => 60, :c => 50, :d => 30}
# #sort_by -> #reverse
hash.sort_by {|k, v| v }.reverse
# => [[:b, 60], [:c, 50], [:a, 40], [:d, 30]]
# #sort_by
hash.sort_by {|k, v| -v }
# => [[:b, 60], [:c, 50], [:a, 40], [:d, 30]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment