#--
# Credit goes to Brian Schröder and Derek for inspiration.
#++
module Enumerable

  # Generates a hash mapping each unique symbol in the array
  # to the absolute frequency it appears.
  def frequency
    probs = Hash.new(0)
    each do | e |
      probs[e] += 1
    end
    probs
  end

end



#  _____         _
# |_   _|__  ___| |_
#   | |/ _ \/ __| __|
#   | |  __/\__ \ |_
#   |_|\___||___/\__|
#
=begin test

  require 'test/unit'

  class TCEnumerable < Test::Unit::TestCase

    def test_frequency
      assert_equal( {'a'=>1,'b'=>1}, %w{a b}.frequency )
      assert_equal( {'tom'=>1,'boy'=>1}, %w{tom boy}.frequency )
    end

  end

=end
