Created
August 14, 2013 14:17
-
-
Save jakecraige/6231468 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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