/** nucomp_hash * */ @JRubyMethod(name = "hash") public IRubyObject hash(ThreadContext context) { return f_xor(context, invokedynamic(context, real, HASH), invokedynamic(context, image, HASH)); }
/** rb_inspect * * The internal helper that ensures a RubyString instance is returned * so dangerous casting can be omitted * Preferred over callMethod(context, "inspect") */ static RubyString inspect(ThreadContext context, IRubyObject object) { return RubyString.objAsString(context, invokedynamic(context, object, INSPECT)); }
@Override public IRubyObject call(ThreadContext context, Ruby runtime, IRubyObject obj, boolean recur) { if (recur) return RubyFixnum.zero(runtime); return invokedynamic(context, obj, HASH); } }
/** nurat_hash * */ @JRubyMethod(name = "hash") public IRubyObject hash(ThreadContext context) { return f_xor(context, (RubyInteger) invokedynamic(context, num, HASH), (RubyInteger) invokedynamic(context, den, HASH)); }
/** * Helper method for checking equality, first using Java identity * equality, and then calling the "==" method. */ protected static boolean equalInternal(final ThreadContext context, final IRubyObject that, final IRubyObject other){ return that == other || invokedynamic(context, that, OP_EQUAL, other).isTrue(); }
/** * Helper method for checking equality, first using Java identity * equality, and then calling the "==" method. */ protected static boolean equalInternal(final ThreadContext context, final IRubyObject that, final IRubyObject other){ return that == other || invokedynamic(context, that, OP_EQUAL, other).isTrue(); }
private IRubyObject equalityInner(ThreadContext context, IRubyObject other, MethodNames equalityCheck) { if (this == other) return context.tru; if (!(other instanceof RubyRange)) return context.fals; RubyRange otherRange = (RubyRange) other; return context.runtime.newBoolean(isExclusive == otherRange.isExclusive && invokedynamic(context, this.begin, equalityCheck, otherRange.begin).isTrue() && invokedynamic(context, this.end, equalityCheck, otherRange.end).isTrue()); }
@Override public IRubyObject uniq(ThreadContext context) { if (!packed()) return super.uniq(context); if (invokedynamic(context, car, MethodNames.HASH).equals(invokedynamic(context, cdr, MethodNames.HASH)) && (car == cdr || invokedynamic(context, car, MethodNames.EQL, cdr).isTrue())) { // Use cdr because it would have been inserted into RubyArray#uniq's RubyHash last return new RubyArrayOneObject(getMetaClass(), cdr); } else { return new RubyArrayTwoObject(this); } }
private void init(ThreadContext context, IRubyObject begin, IRubyObject end, boolean isExclusive) { if (!(begin instanceof RubyFixnum && end instanceof RubyFixnum)) { IRubyObject result = invokedynamic(context, begin, MethodNames.OP_CMP, end); if (result.isNil()) { throw context.runtime.newArgumentError("bad value for range"); } } this.begin = begin; this.end = end; this.isExclusive = isExclusive; this.isInited = true; }
private static IRubyObject rangeLt(ThreadContext context, IRubyObject a, IRubyObject b) { IRubyObject result = invokedynamic(context, a, MethodNames.OP_CMP, b); if (result.isNil()) { return null; } return RubyComparable.cmpint(context, result, a, b) < 0 ? context.tru : null; }
public IRubyObject op_cmp(ThreadContext context, IRubyObject other) { if (this == other || invokedynamic(context, this, OP_EQUAL, other).isTrue()){ return RubyFixnum.zero(context.runtime); } return context.nil; }
public IRubyObject call(ThreadContext ctx, IRubyObject[] largs, Block blk) { IRubyObject larg = packEnumValues(ctx, largs); checkContext(context, ctx, op); IRubyObject v = block.yield(ctx, larg); if (memo == null || RubyComparable.cmpint(ctx, invokedynamic(ctx, v, OP_CMP, memo), v, memo) * sortDirection > 0) { memo = v; result[0] = larg; } return ctx.nil; } });
/** method used for Hash key comparison (specialized for String, Symbol and Fixnum) * * Will by default just call the Ruby method "eql?" */ @Override public boolean eql(IRubyObject other) { return invokedynamic(getRuntime().getCurrentContext(), this, EQL, other).isTrue(); }
private static boolean fastNumEqualInternal(final ThreadContext context, final IRubyObject a, final IRubyObject b) { if (a instanceof RubyFixnum) { if (b instanceof RubyFixnum) return ((RubyFixnum) a).fastEqual((RubyFixnum) b); } else if (a instanceof RubyFloat) { if (b instanceof RubyFloat) return ((RubyFloat) a).fastEqual((RubyFloat) b); } return invokedynamic(context, a, OP_EQUAL, b).isTrue(); }
@JRubyMethod(name = "===", required = 1) @Override public IRubyObject op_eqq(ThreadContext context, IRubyObject other) { if (other instanceof RubyTime) { return context.runtime.newBoolean(RubyNumeric.fix2int(invokedynamic(context, this, OP_CMP, other)) == 0); } return context.fals; }
/** * This override does not do a "checked" dispatch. * * @see RubyBasicObject#equals(Object) */ @Override public boolean equals(Object other) { return other == this || other instanceof IRubyObject && invokedynamic(getRuntime().getCurrentContext(), this, OP_EQUAL, (IRubyObject) other).isTrue(); }
private static IRubyObject rangeLe(ThreadContext context, IRubyObject a, IRubyObject b) { IRubyObject result = invokedynamic(context, a, MethodNames.OP_CMP, b); if (result.isNil()) { return null; } int c = RubyComparable.cmpint(context, result, a, b); if (c == 0) { return RubyFixnum.zero(context.runtime); } return c < 0 ? context.tru : null; }
@Override @JRubyMethod(name = "==") public IRubyObject op_equal(ThreadContext context, IRubyObject other) { Ruby runtime = context.runtime; if (this == other) return runtime.getTrue(); return invokedynamic(context, runtime.newFixnum(status), MethodNames.OP_EQUAL, other); }
/** * This override does not do "checked" dispatch since Object usually has #hash defined. * * @see RubyBasicObject#hashCode() */ @Override public int hashCode() { IRubyObject hashValue = invokedynamic(getRuntime().getCurrentContext(), this, HASH); if (hashValue instanceof RubyFixnum) return (int) RubyNumeric.fix2long(hashValue); return nonFixnumHashCode(hashValue); }
@JRubyMethod(frame = true) public IRubyObject min(ThreadContext context, Block block) { if (block.isGiven()) { return Helpers.invokeSuper(context, this, block); } int cmp = RubyComparable.cmpint(context, invokedynamic(context, begin, MethodNames.OP_CMP, end), begin, end); if (cmp > 0 || (cmp == 0 && isExclusive)) { return context.nil; } return begin; }