vendredi 31 juillet 2015

Hash and values

I came across this Ruby script:

frequency = Hash.new(0)
...
...
file.read.downcase.scan(/\b[a-z]{4,20}\b/){|word| frequency[word] =
frequency[word]+1}

The point I couldn't understand is frequency[word] = frequency[word]+1

Wouldn't frequency[word] give me the word matched? How can we add it to 1?

Aucun commentaire:

Enregistrer un commentaire