示例#1
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;
  }
示例#2
0
  // @RubyLevelMethod(name="uniq!")
  public RubyValue uniq_danger() {
    boolean b = false;
    for (int i = 0; i < array_.size(); ++i) {
      for (int j = i + 1; j < array_.size(); ) {
        if (RubyAPI.testEqual((RubyValue) array_.get(i), (RubyValue) array_.get(j))) {
          array_.remove(j);
          b = true;
        } else {
          ++j;
        }
      }
    }
    if (!b) return RubyConstant.QNIL;

    return this;
    // return b ? this : RubyConstant.QNIL;
  }
示例#3
0
  private RubyValue compare(RubyArray other_array) {
    int length = (size() <= other_array.size()) ? size() : other_array.size();
    for (int i = 0; i < length; ++i) {
      RubyValue v =
          RubyAPI.callPublicOneArgMethod(get(i), other_array.get(i), null, RubyID.unequalID);
      if (!RubyAPI.testEqual(v, ObjectFactory.FIXNUM0)) {
        return v;
      }
    }

    if (size() == other_array.size()) {
      return ObjectFactory.FIXNUM0;
    } else if (size() > other_array.size()) {
      return ObjectFactory.FIXNUM1;
    } else {
      return ObjectFactory.FIXNUM_NEGATIVE_ONE;
    }
  }