Skip to content

Instantly share code, notes, and snippets.

@JunichiIto
Created April 2, 2014 01:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save JunichiIto/9926346 to your computer and use it in GitHub Desktop.
Save JunichiIto/9926346 to your computer and use it in GitHub Desktop.
Another implementation of https://gist.github.com/JunichiIto/9914269
def count_by_word(string)
string
.scan(/\w+/)
.each_with_object(Hash.new(0)){|s, h| h[s] += 1 }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment