Last active
May 27, 2016 23:46
-
-
Save durrellchamorro/2683e326078960cec2371a5b126e98ca to your computer and use it in GitHub Desktop.
Word Count
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(words) | |
@words = words | |
end | |
def word_count | |
count = Hash.new(0) | |
@words.scan(/\b[\w']+\b/) do |word| | |
count[word.downcase] += 1 | |
end | |
count | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment