private static IRubyObject checkMaxInt(ThreadContext context, IRubyObject vmax) { if (!(vmax instanceof RubyFloat)) { IRubyObject v = TypeConverter.checkIntegerType(context, vmax); if (v != context.nil) return v; } return null; }
private static IRubyObject checkMaxInt(ThreadContext context, IRubyObject vmax) { if (!(vmax instanceof RubyFloat)) { IRubyObject v = TypeConverter.checkIntegerType(context, vmax); if (v != context.nil) return v; } return null; }
private static IRubyObject checkMaxInt(ThreadContext context, IRubyObject vmax) { if (!(vmax instanceof RubyFloat)) { IRubyObject v = TypeConverter.checkIntegerType(context.runtime, vmax, "to_int"); if (!v.isNil()) { return v; } } return null; }
private static IRubyObject checkMaxInt(ThreadContext context, IRubyObject vmax) { if (!(vmax instanceof RubyFloat)) { IRubyObject v = TypeConverter.checkIntegerType(context.runtime, vmax, "to_int"); if (!v.isNil()) { return v; } } return null; }
@JRubyMethod(name = "nobits?") public IRubyObject nobits_p(ThreadContext context, IRubyObject other) { IRubyObject mask = TypeConverter.checkIntegerType(context, other); return ((RubyInteger) op_and(context, mask)).zero_p(context); }
@JRubyMethod(name = "allbits?") public IRubyObject allbits_p(ThreadContext context, IRubyObject other) { IRubyObject mask = TypeConverter.checkIntegerType(context, other); return ((RubyInteger) op_and(context, mask)).op_equal(context, mask); }
@JRubyMethod(name = "nobits?") public IRubyObject nobits_p(ThreadContext context, IRubyObject other) { IRubyObject mask = TypeConverter.checkIntegerType(context, other); return ((RubyInteger) op_and(context, mask)).zero_p(context); }
@JRubyMethod(name = "allbits?") public IRubyObject allbits_p(ThreadContext context, IRubyObject other) { IRubyObject mask = TypeConverter.checkIntegerType(context, other); return ((RubyInteger) op_and(context, mask)).op_equal(context, mask); }
@JRubyMethod(name = "anybits?") public IRubyObject anybits_p(ThreadContext context, IRubyObject other) { IRubyObject mask = TypeConverter.checkIntegerType(context, other); return ((RubyInteger) op_and(context, mask)).zero_p(context).isTrue() ? context.fals : context.tru; }
@JRubyMethod(name = "anybits?") public IRubyObject anybits_p(ThreadContext context, IRubyObject other) { IRubyObject mask = TypeConverter.checkIntegerType(context, other); return ((RubyInteger) op_and(context, mask)).zero_p(context).isTrue() ? context.fals : context.tru; }
public static IRubyObject checkIntegerType(Ruby runtime, IRubyObject obj, String method) { if (method.equals("to_int")) return checkIntegerType(runtime.getCurrentContext(), obj); if (obj instanceof RubyFixnum) return obj; if (method.equals("to_i")) { ThreadContext context = runtime.getCurrentContext(); TypeConverterSites sites = sites(context); IRubyObject conv = convertToTypeWithCheck(context, obj, runtime.getInteger(), sites.to_i_checked); return conv instanceof RubyInteger ? conv : runtime.getNil(); } IRubyObject conv = TypeConverter.convertToType(obj, runtime.getInteger(), method, false); return conv instanceof RubyInteger ? conv : runtime.getNil(); }
public static IRubyObject checkIntegerType(Ruby runtime, IRubyObject obj, String method) { if (method.equals("to_int")) return checkIntegerType(runtime.getCurrentContext(), obj); if (obj instanceof RubyFixnum) return obj; if (method.equals("to_i")) { ThreadContext context = runtime.getCurrentContext(); TypeConverterSites sites = sites(context); IRubyObject conv = convertToTypeWithCheck(context, obj, runtime.getInteger(), sites.to_i_checked); return conv instanceof RubyInteger ? conv : runtime.getNil(); } IRubyObject conv = TypeConverter.convertToType(obj, runtime.getInteger(), method, false); return conv instanceof RubyInteger ? conv : runtime.getNil(); }
@JRubyMethod(name = "gets", writes = FrameField.LASTLINE, compat = RUBY1_9) public IRubyObject gets19(ThreadContext context, IRubyObject separator, IRubyObject limit_arg) { Ruby runtime = context.runtime; long limit = limit_arg.isNil() ? -1 : RubyNumeric.fix2long(TypeConverter.checkIntegerType(runtime, limit_arg, "to_int")); IRubyObject result = getline(context, separator(runtime, separator), limit); if (!result.isNil()) context.setLastLine(result); return result; }
@JRubyMethod(name = "gets", writes = FrameField.LASTLINE, compat = RUBY1_9) public IRubyObject gets19(ThreadContext context, IRubyObject separator, IRubyObject limit_arg) { Ruby runtime = context.runtime; long limit = limit_arg.isNil() ? -1 : RubyNumeric.fix2long(TypeConverter.checkIntegerType(runtime, limit_arg, "to_int")); IRubyObject result = getline(context, separator(runtime, separator), limit); if (!result.isNil()) context.setLastLine(result); return result; }
@JRubyMethod(name = "gets", writes = FrameField.LASTLINE, compat = RUBY1_9) public IRubyObject gets19(ThreadContext context, IRubyObject arg) { Ruby runtime = context.runtime; ByteList separator; long limit = -1; IRubyObject test = TypeConverter.checkIntegerType(runtime, arg, "to_int"); if (test instanceof RubyInteger) { limit = RubyInteger.fix2long(test); separator = separator(runtime); } else { separator = separator(runtime, arg); } IRubyObject result = getline(context, separator, limit); if (!result.isNil()) context.setLastLine(result); return result; }
@JRubyMethod(name = "gets", writes = FrameField.LASTLINE, compat = RUBY1_9) public IRubyObject gets19(ThreadContext context, IRubyObject arg) { Ruby runtime = context.runtime; ByteList separator; long limit = -1; IRubyObject test = TypeConverter.checkIntegerType(runtime, arg, "to_int"); if (test instanceof RubyInteger) { limit = RubyInteger.fix2long(test); separator = separator(runtime); } else { separator = separator(runtime, arg); } IRubyObject result = getline(context, separator, limit); if (!result.isNil()) context.setLastLine(result); return result; }
@JRubyMethod(meta = true) public static IRubyObject linger(ThreadContext context, IRubyObject self, IRubyObject vonoff, IRubyObject vsecs) { ProtocolFamily family = ProtocolFamily.PF_UNSPEC; SocketLevel level = SocketLevel.SOL_SOCKET; SocketOption option = SocketOption.SO_LINGER; int coercedVonoff; if (!TypeConverter.checkIntegerType(context, vonoff).isNil()) { coercedVonoff = vonoff.convertToInteger().getIntValue(); } else { coercedVonoff = vonoff.isTrue() ? 1 : 0; } ByteList data = packLinger(coercedVonoff, vsecs.convertToInteger().getIntValue()); return new Option(context.getRuntime(), family, level, option, data); }
@JRubyMethod(meta = true) public static IRubyObject linger(ThreadContext context, IRubyObject self, IRubyObject vonoff, IRubyObject vsecs) { ProtocolFamily family = ProtocolFamily.PF_UNSPEC; SocketLevel level = SocketLevel.SOL_SOCKET; SocketOption option = SocketOption.SO_LINGER; int coercedVonoff; if (!TypeConverter.checkIntegerType(context, vonoff).isNil()) { coercedVonoff = vonoff.convertToInteger().getIntValue(); } else { coercedVonoff = vonoff.isTrue() ? 1 : 0; } ByteList data = packLinger(coercedVonoff, vsecs.convertToInteger().getIntValue()); return new Option(context.getRuntime(), family, level, option, data); }
private IRubyObject stepCommon19(ThreadContext context, IRubyObject step, Block block) { Ruby runtime = context.runtime; if (begin instanceof RubyFixnum && end instanceof RubyFixnum && step instanceof RubyFixnum) { fixnumStep(context, runtime, ((RubyFixnum)step).getLongValue(), block); } else if (begin instanceof RubyFloat || end instanceof RubyFloat || step instanceof RubyFloat) { RubyNumeric.floatStep19(context, runtime, begin, end, step, isExclusive, block); } else if (begin instanceof RubyNumeric || !TypeConverter.checkIntegerType(runtime, begin, "to_int").isNil() || !TypeConverter.checkIntegerType(runtime, end, "to_int").isNil()) { numericStep19(context, runtime, step, block); } else { IRubyObject tmp = begin.checkStringType(); if (!tmp.isNil()) { StepBlockCallBack callback = new StepBlockCallBack(block, RubyFixnum.one(runtime), step); Block blockCallback = CallBlock.newCallClosure(this, runtime.getRange(), Arity.singleArgument(), callback, context); ((RubyString)tmp).uptoCommon19(context, end, isExclusive, blockCallback); } else { if (!begin.respondsTo("succ")) throw runtime.newTypeError("can't iterate from " + begin.getMetaClass().getName()); // range_each_func(range, step_i, b, e, args); rangeEach(context, new StepBlockCallBack(block, RubyFixnum.one(runtime), step)); } } return this; }
private IRubyObject stepCommon19(ThreadContext context, IRubyObject step, Block block) { Ruby runtime = context.runtime; if (begin instanceof RubyFixnum && end instanceof RubyFixnum && step instanceof RubyFixnum) { fixnumStep(context, runtime, ((RubyFixnum)step).getLongValue(), block); } else if (begin instanceof RubyFloat || end instanceof RubyFloat || step instanceof RubyFloat) { RubyNumeric.floatStep19(context, runtime, begin, end, step, isExclusive, block); } else if (begin instanceof RubyNumeric || !TypeConverter.checkIntegerType(runtime, begin, "to_int").isNil() || !TypeConverter.checkIntegerType(runtime, end, "to_int").isNil()) { numericStep19(context, runtime, step, block); } else { IRubyObject tmp = begin.checkStringType(); if (!tmp.isNil()) { StepBlockCallBack callback = new StepBlockCallBack(block, RubyFixnum.one(runtime), step); Block blockCallback = CallBlock.newCallClosure(this, runtime.getRange(), Arity.singleArgument(), callback, context); ((RubyString)tmp).uptoCommon19(context, end, isExclusive, blockCallback); } else { if (!begin.respondsTo("succ")) throw runtime.newTypeError("can't iterate from " + begin.getMetaClass().getName()); // range_each_func(range, step_i, b, e, args); rangeEach(context, new StepBlockCallBack(block, RubyFixnum.one(runtime), step)); } } return this; }