Struggling with Iterating Over the Hash


#1

I've been stuck on this for awhile and I would really appreciate some guidance on this task. I keep getting 'undefined local variable or method `words' for #.' I'm not sure what to do. Here's my code:

puts "good morning"
text = gets.chomp

word = text.split (" ")
puts "good morning"

frequencies = Hash.new(0)

words.each { |word| frequencies[word] +=1}
frequencies = frequencies.sort_by { |a, b| b }
frequencies.reverse!

frequencies.each do |word, frequency|
puts word + " " + frequency.to_s
end

Thank you in advance!


#2

words = text.split (" ") instead of word = text.split (" "). Bad variable naming.