Create a Histogram: 7. Iterating over the hash -- Help!? --


Okay, I’ve been on this lesson for way too long now… I’ve read every post on this forum discussing this one, referred back to every last step and “hint”, but my code isn’t working and I’m finally throwing in the towel… somebody please help :expressionless:

Here is my code:

puts "Say something… "
text = gets.chomp

words = text.split (" ")

frequencies =
words.each { |word| frequencies[word] += 1 }
frequencies = frequencies.sort_by {[word, frequency]}
frequencies.each do |word, frequency|
puts word + " " + frequency.to_s

…AND here is the error I am getting repeatedly. Or at least, the best error I’m getting. I’ve made many changes, some of which yielded in worse errors, so this seems to be the cleanest my code has gotten.


This is where the error is thrown. The block parameter should be written between two pipes, not in an array.

... =  ... .sort_by {|word, frequency|}


Wow, THANK YOU… .You have no idea how long I had been staring at that code.