
class Array

  # Delete multiple values from array given
  # indexes or index range.
  #
  #   a = [1,2,3,4]
  #   a.delete_values_at(1,2)   #=> [2,3]
  #   a                         #=> [1,4]
  #   a = [1,2,3,4]
  #   a.delete_values_at(0..2)  #=> [1,2,3]
  #   a                         #=> [4]
  #

  def delete_values_at(*selectors)
    idx = []
    selectors.each{ |i|
      case i
      when Range
        idx.concat( i.to_a )
      else
        idx << i.to_i
      end
    }
    idx.uniq!
    dvals = values_at(*idx)
    idx = (0...size).to_a - idx
    self.replace( values_at(*idx) )
    return dvals
  end

end


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

  require 'test/unit'

  class TCArray < Test::Unit::TestCase

    def test_delete_values_at
      a = [1,2,3,4]
      assert_equal( [2,3], a.delete_values_at(1,2) )
      assert_equal( [1,4], a )
      a = [1,2,3,4]
      assert_equal( [1,2,3], a.delete_values_at(0..2) )
      assert_equal( [4], a )
    end

  end

=end

