Ejemplo n.º 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;
 }
Ejemplo n.º 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;
 }
Ejemplo n.º 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;
 }
Ejemplo n.º 4
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;
  }
Ejemplo n.º 5
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;
 }
Ejemplo n.º 6
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;
  }
Ejemplo n.º 7
0
  // @RubyLevelMethod(name="&")
  public RubyArray and(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 (other.include(v) == RubyConstant.QTRUE && a.include(v) == RubyConstant.QFALSE) {
        a.add(v);
      }
    }
    return a;
  }