Created
January 10, 2014 21:09
-
-
Save breethomas/8362657 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 | |
attr_reader :expression | |
def initialize(expression) | |
@expression = expression | |
end | |
def word_count | |
words.each_with_object(Hash.new(0)) do |word, count| | |
count[word] += 1 | |
end | |
end | |
private | |
def words | |
expression.downcase.scan(/[\w']+/) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment