Skip to content

Instantly share code, notes, and snippets.

@breethomas
Created January 10, 2014 21:09
Show Gist options
  • Save breethomas/8362657 to your computer and use it in GitHub Desktop.
Save breethomas/8362657 to your computer and use it in GitHub Desktop.
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