The code I have written is practically the same as the one, which allows you to pass the exercise. Even though, after I have typed in my phrase, I keep getting this error message: “undefined method `’ for nil:NilClass”
This is my code:
puts "Write a text to analyze"
text = gets.chomp
words = text.split
frequencies = Hash.new
words.each do|word| frequencies[word] += 1
frequencies = frequencies.sort_by do |word, frequency|
frequencies.each do |word, frequency|
puts word + " " + frequency.to_s
What am I doing wrong, where is that wrong bit?