Skip to content

Instantly share code, notes, and snippets.

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