ruby - word-count

This commit is contained in:
2018-09-19 10:43:56 -04:00
parent 3a6122e886
commit 0489fdc1af
3 changed files with 138 additions and 0 deletions

View File

@ -0,0 +1,14 @@
class Phrase
def initialize(phrase)
@phrase = phrase
end
def word_count
counts = {}
@phrase.scan(/\w+(?:'\w)*/).each do |word|
word.downcase!
counts[word] = counts[word].to_i + 1
end
counts
end
end