Q:

How does a program recognize the difference between frequency and frequencies as variable names?

puts "Get Text: "
text = gets.chomp

words = text.split

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

A:

This is actually worth answering from a newbie perspective, but only if we look at it from Ruby and Rails. A newcomer might get confused by the fact that in Ruby frequency and frequencies are two completely different variables. BUT in Rails, a newcomer is taught that Rails automatically pluralizes and singularizes for us in many instances. We create a tables
class Frequency < ActiveRecord::Base
belongs_to :radio

end

class Radio < ActiveRecord::Base
has_many :frequencies

end

You can then do things like:
$> r = Radio.first
$> r.frequencies

    Frequency Load (1.8ms)  SELECT "frequencies".* FROM "frequencies" WHERE  
"frequencies"."radio_id" = 1

Pluralization in Rails is a nice feature that can confuse a new user who is also new to Ruby. The same can be said for Hash with Indifferent Access, I know that one confused me at first.

