class Hamster::Vector

def put(index, item = yield(get(index)))

Returns:
  • (Vector) -

Parameters:
  • index (Integer) -- The index to update. May be negative.
  • item (Object) -- The object to insert into that position

Other tags:
    Yield: - Once with the existing value at the given `index`.

Overloads:
  • put(index)
  • put(index, item)
def put(index, item = yield(get(index)))
  raise IndexError, "index #{index} outside of vector bounds" if index < -@size
  index += @size if index < 0
  if index > @size
    suffix = Array.new(index - @size, nil)
    suffix << item
    replace_suffix(@size, suffix)
  else
    update_root(index, item)
  end
end