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; }
private RubyArray insert(int index, RubyArray a) { for (int i = array_.size(); i < index; ++i) { array_.add(RubyConstant.QNIL); } array_.addAll(index, a.array_); return this; }
public RubyArray expand(RubyValue v) { if (v instanceof RubyArray) { // [5,6,*[1, 2]] array_.addAll(((RubyArray) v).array_); } else { // [5,6,*1], [5,6,*nil] array_.add(v); } return this; }
// @RubyLevelMethod(name="unshift") public RubyArray unshift(RubyArray value) { array_.addAll(0, value.array_); return this; }
// @RubyLevelMethod(name="concat") public RubyArray concat(RubyValue v) { RubyArray ary = v.toAry(); array_.addAll(ary.array_); return this; }