Refine search
@JRubyMethod(name = "==") public IRubyObject eq(ThreadContext context, IRubyObject other) { Ruby runtime = context.runtime; if (!(other instanceof RubyMessage)) return runtime.getFalse(); RubyMessage message = (RubyMessage) other; if (descriptor != message.descriptor) { return runtime.getFalse(); } for (Descriptors.FieldDescriptor fdef : descriptor.getFields()) { IRubyObject thisVal = getField(context, fdef); IRubyObject thatVal = message.getField(context, fdef); IRubyObject ret = thisVal.callMethod(context, "==", thatVal); if (!ret.isTrue()) { return runtime.getFalse(); } } return runtime.getTrue(); }
public boolean checkFinite(ThreadContext context, IRubyObject value) { if (value instanceof RubyInteger || value instanceof RubyRational) { return true; } if (value instanceof RubyFloat) { return ((RubyFloat) value).finite_p().isTrue(); } if (value instanceof RubyRational) { return true; } return sites(context).finite.call(context, value, value).isTrue(); }
@JRubyMethod public IRubyObject keep_if(final ThreadContext context, Block block) { if ( ! block.isGiven() ) { return enumeratorizeWithSize(context, this, "keep_if", enumSize()); } Iterator<IRubyObject> it = elementsOrdered().iterator(); while ( it.hasNext() ) { IRubyObject elem = it.next(); if ( ! block.yield(context, elem).isTrue() ) deleteImplIterator(elem, it); // it.remove } return this; }
public IRubyObject detectCommon(ThreadContext context, IRubyObject ifnone, Block block) { for (int i = 0; i < realLength; i++) { IRubyObject value = eltOk(i); if (block.yield(context, value).isTrue()) return value; } return ifnone != null ? sites(context).call.call(context, ifnone, ifnone) : context.nil; }
/** * The != method implemented for BasicObject. * * @param context thread context * @param other other object * @return false if this == other, true otherwise */ @JRubyMethod(name = "!=", required = 1) public IRubyObject op_not_equal(ThreadContext context, IRubyObject other) { return context.runtime.newBoolean(!sites(context).op_equal.call(context, this, this, other).isTrue()); }
@JRubyMethod(name = "method_missing", rest = true) public IRubyObject methodMissing(ThreadContext context, IRubyObject[] args) { if (args.length == 1) { RubyDescriptor rubyDescriptor = (RubyDescriptor) getDescriptor(context, metaClass); IRubyObject oneofDescriptor = rubyDescriptor.lookupOneof(context, args[0]); if (oneofDescriptor.isNil()) { if (!hasField(args[0])) { return Helpers.invokeSuper(context, this, metaClass, "method_missing", args, Block.NULL_BLOCK); } return index(context, args[0]); } RubyOneofDescriptor rubyOneofDescriptor = (RubyOneofDescriptor) oneofDescriptor; Descriptors.FieldDescriptor fieldDescriptor = oneofCases.get(rubyOneofDescriptor.getOneofDescriptor()); if (fieldDescriptor == null) return context.runtime.getNil(); return context.runtime.newSymbol(fieldDescriptor.getName()); } else { // fieldName is RubySymbol RubyString field = args[0].asString(); RubyString equalSign = context.runtime.newString(Utils.EQUAL_SIGN); if (field.end_with_p(context, equalSign).isTrue()) { field.chomp_bang(context, equalSign); } if (!hasField(field)) { return Helpers.invokeSuper(context, this, metaClass, "method_missing", args, Block.NULL_BLOCK); } return indexSet(context, field, args[1]); } }
@JRubyMethod public IRubyObject delete_if(final ThreadContext context, Block block) { if ( ! block.isGiven() ) { return enumeratorizeWithSize(context, this, "delete_if", enumSize()); } Iterator<IRubyObject> it = elementsOrdered().iterator(); while ( it.hasNext() ) { IRubyObject elem = it.next(); if ( block.yield(context, elem).isTrue() ) deleteImplIterator(elem, it); // it.remove } return this; }
public IRubyObject detectCommon(ThreadContext context, IRubyObject ifnone, Block block) { for (int i = 0; i < realLength; i++) { IRubyObject value = eltOk(i); if (block.yield(context, value).isTrue()) return value; } return ifnone != null ? sites(context).call.call(context, ifnone, ifnone) : context.nil; }
/** * The != method implemented for BasicObject. * * @param context thread context * @param other other object * @return false if this == other, true otherwise */ @JRubyMethod(name = "!=", required = 1) public IRubyObject op_not_equal(ThreadContext context, IRubyObject other) { return context.runtime.newBoolean(!sites(context).op_equal.call(context, this, this, other).isTrue()); }
@JRubyMethod(name = "abort_on_exception=", required = 1) public IRubyObject abort_on_exception_set(IRubyObject val) { abortOnException = val.isTrue(); return val; }
@JRubyMethod public IRubyObject delete_if(final ThreadContext context, Block block) { if ( ! block.isGiven() ) { return enumeratorizeWithSize(context, this, "delete_if", enumSize()); } Iterator<IRubyObject> it = elementsOrdered().iterator(); while ( it.hasNext() ) { IRubyObject elem = it.next(); if ( block.yield(context, elem).isTrue() ) deleteImplIterator(elem, it); // it.remove } return this; }
private static void duckUpto(ThreadContext context, IRubyObject from, IRubyObject to, Block block) { Ruby runtime = context.runtime; IRubyObject i = from; RubyFixnum one = RubyFixnum.one(runtime); while (true) { if (sites(context).op_gt.call(context, i, i, to).isTrue()) { break; } block.yield(context, i); i = sites(context).op_plus.call(context, i, i, one); } }
/** num_abs * */ @JRubyMethod(name = "abs") public IRubyObject abs(ThreadContext context) { if (sites(context).op_lt.call(context, this, this, RubyFixnum.zero(context.runtime)).isTrue()) { return sites(context).op_uminus.call(context, this, this); } return this; }
@JRubyMethod(name = "autoclose=") public IRubyObject autoclose_set(ThreadContext context, IRubyObject autoclose) { setAutoclose(autoclose.isTrue()); return context.nil; }
@JRubyMethod public IRubyObject keep_if(final ThreadContext context, Block block) { if ( ! block.isGiven() ) { return enumeratorizeWithSize(context, this, "keep_if", enumSize()); } Iterator<IRubyObject> it = elementsOrdered().iterator(); while ( it.hasNext() ) { IRubyObject elem = it.next(); if ( ! block.yield(context, elem).isTrue() ) deleteImplIterator(elem, it); // it.remove } return this; }