Question : set default value in hash
Answered by : mattias-v
# iterate over default value (0) in the hash frequencies
frequencies = Hash.new(0) #sets default value to 0, so iteration works.
words.each { |word| frequencies[word] += 1 }
Source : https://stackoverflow.com/questions/16159370/ruby-hash-default-value-behavior | Last Update : Fri, 14 Oct 22