From: 7stud -- Date: 2012-12-29T05:14:24+09:00 Subject: Re: Ruby Koans regarding Hashes. > ...which I currently have no idea how that could be useful, but it is > still interesting... heh string = "Hello world, hello mars, goodbye world." word_count_for = Hash.new(0) string.scan(/\b \w+ \b/x) do |word| word = word.downcase word_count_for[word] += 1 end p word_count_for --output:-- {"hello"=>2, "world"=>2, "mars"=>1, "goodbye"=>1} -- Posted via http://www.ruby-forum.com/.