Example #1
0
 // @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;
 }
Example #2
0
 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;
 }
Example #3
0
 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;
 }
Example #4
0
 // @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;
 }
Example #5
0
  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;
  }
Example #6
0
 // @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;
 }
Example #7
0
  // @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;
  }