【澳门葡京备用网址】Accept dashes and apostrophes as parts of words.

class String
  def word_count
    frequencies = Hash.new(0)
    downcase.scan(/[-'\w]+/) { |word, ignore| frequencies[word] += 1 }
    return frequencies
  end
end

%{'this is a test.'}.word_count

相关文章

发表评论

电子邮件地址不会被公开。 必填项已用*标注

*
*
Website