kernel/common/array.rb
# Deletes the element(s) given by an index (optionally with a length)
# or by a range. Returns the deleted object, subarray, or nil if the
# index is out of range. Equivalent to:
Deletes the element(s) given by an index (optionally with a length)
or by a range. Returns the deleted object, subarray, or nil if the
index is out of range. Equivalent to.
Deletes the element ( s ) given by an index ( optionally with a length ) or by a range . Returns the deleted object subarray or nil if the index is out of range . Equivalent to .
def slice!(*args)
    out = self[*args]
    if !(Range === args[0])
      args[0] = Type.coerce_to args[0], Integer, :to_int
      args[0] = args[0] + self.length if args[0] < 0
      if args.size == 1
        return out unless args[0] >= 0 && args[0] < self.length
        args << 1
      end
    end
    self[*args] = []
    out
  end
def slice! ( * args ) out = self [ * args ] if ! ( Range === args [ 0 ] ) args [ 0 ] = Type . coerce_to args [ 0 ] , Integer , :to_int args [ 0 ] = args [ 0 ] + self . length if args [ 0 ] < 0 if args . size == 1 return out unless args [ 0 ] >= 0 && args [ 0 ] < self . length args << 1 end end self [ * args ] = [ ] out end
Deletes the element(s) given by an index (optionally with a length)
or by a range.
Deletes the element ( s ) given by an index ( optionally with a length ) or by a range .
# make sure that negative values are not passed through to the # []= assignment # This is to match the MRI behaviour of not extending the array # with nil when specifying an index greater than the length # of the array.
args
<not_specific>