Skip to content

Instantly share code, notes, and snippets.

@jonathanhudak
Created June 14, 2014 22:36
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 jonathanhudak/389f21901ae647ae627a to your computer and use it in GitHub Desktop.
Save jonathanhudak/389f21901ae647ae627a to your computer and use it in GitHub Desktop.
sort array of hashes
arrayOfHashes = [{'count' => 5}, {'count' => 3}, {'count' => 8}];
puts arrayOfHashes.sort_by { |hash| hash[:count]}
@calebkm
Copy link

calebkm commented Jun 14, 2014

The issue here is that :count is not the same as 'count'.

@calebkm
Copy link

calebkm commented Jun 14, 2014

If you change hash[:count] to hash['count'] this works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment