Why should I use substitution operator when i sort the Hash


my code is below

puts "input the text : "
text = gets.chomp
words = text.split(" ")
frequencies = Hash.new(0)
words.each do |word|
frequencies[word] += 1
frequencies = frequencies.sort_by do |word, frequency|

Here i have a question. I heard that ruby is object oriented language. Then i think i can sort the Hash without substitution operator, like

frequencies.sort_by do |word, frequency|

I think Hash is also object, therefore it has the "sort_by" method and I think it should work without substitution operator. But.... It's not work. :sob:
Is there anybody to help me understanding?


Yes, it does work. The code your proposed sorts the hash according to the values in ascending order, then your reverse will give a hash in the descending order.