// @RubyLevelMethod(name="push") public RubyArray multiPush(RubyArray args) { // for (RubyValue v : args) { for (Iterator iter = args.iterator(); iter.hasNext(); ) { RubyValue v = (RubyValue) iter.next(); this.array_.add(v); } return this; }
public int hashCode() { int hash = 0; // for (RubyValue v : array_) { for (Iterator iter = array_.iterator(); iter.hasNext(); ) { RubyValue v = (RubyValue) iter.next(); hash += v.hashCode(); } return hash; }
private RubyArray minus(RubyArray other) { RubyArray a = this.copy(); // for (RubyValue v : other) { for (Iterator iter = other.iterator(); iter.hasNext(); ) { RubyValue v = (RubyValue) iter.next(); a.remove(v); } return a; }
// @RubyLevelMethod(name="|") public RubyArray or(RubyValue value) { RubyArray other = value.toAry(); RubyArray a = new RubyArray(); // for (RubyValue v : array_) { for (Iterator iter = array_.iterator(); iter.hasNext(); ) { RubyValue v = (RubyValue) iter.next(); if (a.include(v) == RubyConstant.QFALSE) { a.add(v); } } // for (RubyValue v : other) { for (Iterator iter = other.iterator(); iter.hasNext(); ) { RubyValue v = (RubyValue) iter.next(); if (a.include(v) == RubyConstant.QFALSE) { a.add(v); } } return a; }
public RubyArray copy() { RubyArray resultArray = new RubyArray(array_.size()); // for (RubyValue v : array_) { for (Iterator iter = array_.iterator(); iter.hasNext(); ) { RubyValue v = (RubyValue) iter.next(); resultArray.add(v); } return resultArray; }
// @RubyLevelMethod(name="each") public RubyValue each(RubyBlock block) { // for (RubyValue item : array_) { for (Iterator iter = array_.iterator(); iter.hasNext(); ) { RubyValue item = (RubyValue) iter.next(); RubyValue v = block.invoke(this, item); if (block.breakedOrReturned()) { return v; } } return this; }
// @RubyLevelMethod(name="include?") public RubyValue include(RubyValue v) { // for (RubyValue value : array_) { for (Iterator iter = array_.iterator(); iter.hasNext(); ) { RubyValue value = (RubyValue) iter.next(); if (RubyAPI.testEqual(value, v)) { return RubyConstant.QTRUE; } } return RubyConstant.QFALSE; }