Skip to content

Instantly share code, notes, and snippets.

@mileszs
Created November 14, 2013 01:40
Show Gist options
  • Save mileszs/7459840 to your computer and use it in GitHub Desktop.
Save mileszs/7459840 to your computer and use it in GitHub Desktop.
class Phrase
def initialize(value)
@phrase = value
end
def word_count
Hash.new(0).tap do |count|
@phrase.split(/[^[:alnum:]]+/).each do |word|
count[word.downcase] += 1
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment