// @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; }
// @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; }
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; } }