Skip to content

Instantly share code, notes, and snippets.

@aereal
Created June 4, 2010 12:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aereal/425353 to your computer and use it in GitHub Desktop.
Save aereal/425353 to your computer and use it in GitHub Desktop.
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