Ruby


#1

I can't seem to get this code to work, despite reading previous answers on the forum. Can anyone advise a newbie, please?

puts "What's your text? "
text = gets.chomp

words = text.split
frequencies = Hash.new(0)
words.each do { |word| frequencies[word] += 1 }
frequencies = frequencies.sort_by {|a, b| b}
frequencies.reverse!
end

Also, I have followed the logic of the previous lessons just fine, but this one eludes me. Clarification would be appreciated. Thank you.


#2

The above is throwing an error because it is not a part of any code body. The do has a block.

Otherwise, your code looks fine.