返回顶部

收藏

Count words for a string with quotation marks

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

%{'I have no shame,' I said.}.word_count

标签:Ruby,String

收藏

0人收藏

支持

0

反对

0

发表评论