6. Can't convert string into integer


#1

Says can't convert string into integer as the error

puts "Can I have some text?"
text = gets.chomp
words = text.split(" ")
words.each { |word| frequencies[word] += 1}
frequencies = Hash.new(0)
frequencies = frequencies.sort_by {|k, v| v}
frequencies.reverse!

#2

I don't know if this matters, but you're assigning the key/value pairs to frequencies before you actually create the new hash.

writing

after you write

might be resetting frequencies to a new empty hash with a default value of 0?

I'm actually not sure about this but it might be worth a try to reverse those two lines.


#3

That fixed it! Thank you so much!