#--
# Martin DeMello
#++

require 'enumerator'

module Enumerable
  def eachn(&block)
    n = block.arity.abs
    each_slice(n) {|i| block.call(*i)}
  end
end


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

  require 'test/unit'

  class TCEnumerable < Test::Unit::TestCase

    def test_eachn
      x = []
      [1,2,3,4].eachn{ |a,b| x << [a,b] }
      o = [[1,2],[3,4]]
      assert_equal( o, x )

      x = []
      [1,2,3,4,5].eachn{ |a,b,c| x << [a,b,c] }
      o = [[1,2,3],[4,5,nil]]
      assert_equal( o, x )
    end

  end

=end
