Skip to content

Instantly share code, notes, and snippets.

@norcal82
Created March 3, 2016 19:41
Show Gist options
  • Save norcal82/6fdd3e62f97c39df274f to your computer and use it in GitHub Desktop.
Save norcal82/6fdd3e62f97c39df274f to your computer and use it in GitHub Desktop.
Ruby Hash Methods
def group_by_key_with_counts collection
collection.inject {|a, b| a.merge(b) { |_, old_val, new_val| old_val + new_val} }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment