
class Array

  # Returns the middle element(s) of an array. Even-sized arrays,
  # not having an exact middle, returns a two-element array
  # of the two middle elements.
  #
  #   [1,2,3,4,5].mid        #=> 3
  #   [1,2,3,4,5,6].mid      #=> [3,4]
  #
  # In contrast to #mid which utilizes an offset.
  def middle
    if size % 2 == 0
      [ at((size/2)-1), at(size/2) ]
    else
      at(size/2)
    end
  end

end



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

  require 'test/unit'

  class TCArray < Test::Unit::TestCase

    def test_middle
      a = [1,2,3,4,5]
      b = [1,2,3,4,5,6]
      assert_equal( 3, a.middle )
      assert_equal( [3,4], b.middle )
    end

  end

=end
