ruby - word-count
This commit is contained in:
14
ruby/word-count/word_count.rb
Normal file
14
ruby/word-count/word_count.rb
Normal 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
|
Reference in New Issue
Block a user