Skip to content

Instantly share code, notes, and snippets.

@makaroni4
Created February 27, 2016 22:57
Show Gist options
  • Save makaroni4/30d1e9954ec139aa7933 to your computer and use it in GitHub Desktop.
Save makaroni4/30d1e9954ec139aa7933 to your computer and use it in GitHub Desktop.
input = ["red", "green", "blue", "red", "blue"]
output = input.each_with_object(Hash.new(0)) do |word, o|
o[word] += 1
end
p output
# {"red"=>2, "green"=>1, "blue"=>2}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment