Skip to content

Instantly share code, notes, and snippets.

@jakecraige
Created August 14, 2013 14:17
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 jakecraige/6231468 to your computer and use it in GitHub Desktop.
Save jakecraige/6231468 to your computer and use it in GitHub Desktop.
class Phrase
def initialize(string)
@words = string.downcase.scan(/\w+/)
end
def word_count
@words.inject({}) do |results, word|
results.merge!({ word => 1 }) { |_, old, _| old + 1 }
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment