
module Enumerable

  # Count the number of items in an enuerable equal (==)
  # to the given object.
  #
  #   e = [ 'a', '1', 'a' ]
  #   e.count('1')    #=> 1
  #   e.count('a')    #=> 2
  #
  # Count can also handle multiple-valued blocks.
  #
  #   e = { 'a' => 2, 'a' => 2, 'b' => 1 }
  #   e.count('a',2)  #=> 1
  #
  def count(*c)
    self.select{ |*i| i == c }.length
  end

end



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

  require 'test/unit'

  class TC01 < Test::Unit::TestCase

    def test_001
      e = [ 'a', '1', 'a' ]
      assert_equal( 1, e.count('1') )
      assert_equal( 2, e.count('a') )
    end

    def test_002
      e = [ ['a',2], ['a',2], ['a',2], ['b',1] ]
      assert_equal( 3, e.count(['a',2]) )
    end

    def test_003
      e = { 'a' => 2, 'a' => 2, 'b' => 1 }
      assert_equal( 1, e.count('a',2) )
    end

  end

=end