public RubyValue replace(int start, int length, RubyValue value) { int index = getRealIndex(start); if (value == RubyConstant.QNIL) { for (int i = 0; i < length; i++) { array_.remove(index); } return value; } if (length < 0) { throw new RubyException(RubyRuntime.IndexErrorClass, "negative length (" + length + ")"); } else if (0 == length) { if (value instanceof RubyArray) { array_.addAll(index, ((RubyArray) value).array_); } else { array_.add(index, value); } } else { for (int i = 0; i < length - 1; ++i) { array_.remove(index); } if (value instanceof RubyArray) { array_.remove(index); array_.addAll(index, ((RubyArray) value).array_); } else { array_.set(index, value); } } return value; }
public RubyValue set(int start, RubyValue value) { int index = getRealIndex(start); if (index < array_.size()) { array_.set(index, value); } else { for (int i = array_.size(); i < index; ++i) { array_.add(RubyConstant.QNIL); } array_.add(value); } return value; }