Refine search
private void aggregateDimensions(IRubyObject[] sizes) { int[] newDimensions = new int[dimensions.length + sizes.length]; System.arraycopy(dimensions, 0, newDimensions, 0, dimensions.length); for (int i = 0; i < sizes.length; i++) { IRubyObject size = sizes[i]; int intSize = (int) size.convertToInteger().getLongValue(); newDimensions[i + dimensions.length] = intSize; } dimensions = newDimensions; } }
private static int interpretSeekWhence(IRubyObject whence) { if (whence instanceof RubySymbol) { String string = whence.toString(); if ("SET".equals(string)) return PosixShim.SEEK_SET; if ("CUR".equals(string)) return PosixShim.SEEK_CUR; if ("END".equals(string)) return PosixShim.SEEK_END; } return (int) whence.convertToInteger().getLongValue(); }
@Override public IRubyObject set(IRubyObject value) { int line = (int)value.convertToInteger().getLongValue(); runtime.setCurrentLine(line); return value; }
static long getDay(ThreadContext context, IRubyObject day, final long[] rest) { long d = day.convertToInteger().getLongValue(); if (!(day instanceof RubyInteger) && day instanceof RubyNumeric) { // Rational|Float RubyRational rat = ((RubyNumeric) day).convertToRational(); long num = rat.getNumerator().getLongValue(); long den = rat.getDenominator().getLongValue(); rest[0] = (num - d * den); rest[1] = den; } return d; }
static int getHour(ThreadContext context, IRubyObject hour, final long[] rest) { long h = hour.convertToInteger().getLongValue(); long i = 0; final long r0 = rest[0], r1 = rest[1]; if (r0 != 0) { i = (24 * r0) / r1; rest[0] = (24 * r0) - (i * r1); } addRationalModToRest(context, hour, h, rest); h += i; return (int) (h < 0 ? h + 24 : h); // JODA will handle invalid value }
static long getDay(ThreadContext context, IRubyObject day, final long[] rest) { long d = day.convertToInteger().getLongValue(); if (!(day instanceof RubyInteger) && day instanceof RubyNumeric) { // Rational|Float RubyRational rat = ((RubyNumeric) day).convertToRational(); long num = rat.getNumerator().getLongValue(); long den = rat.getDenominator().getLongValue(); rest[0] = (num - d * den); rest[1] = den; } return d; }
private static long normIntValue(IRubyObject val, final int negOffset) { long v; if (val instanceof RubyFixnum) { v = ((RubyFixnum) val).getLongValue(); } else { v = val.convertToInteger().getLongValue(); } return (v < 0) ? v + negOffset : v; }
static int getMinute(ThreadContext context, IRubyObject val, final long[] rest) { long v = val.convertToInteger().getLongValue(); long i = 0; final long r0 = rest[0], r1 = rest[1]; if (r0 != 0) { i = (60 * r0) / r1; rest[0] = (60 * r0) - (i * r1); } addRationalModToRest(context, val, v, rest); v += i; return (int) (v < 0 ? v + 60 : v); // JODA will handle invalid value }
@JRubyMethod(name = "set_last_exit_status", meta = true) // used from JRuby::ProcessManager public static IRubyObject set_last_exit_status(ThreadContext context, IRubyObject recv, IRubyObject status, IRubyObject pid) { RubyProcess.RubyStatus processStatus = RubyProcess.RubyStatus.newProcessStatus(context.runtime, status.convertToInteger().getLongValue(), pid.convertToInteger().getLongValue() ); context.setLastExitStatus(processStatus); return processStatus; }
private static int simpleIntDiff(IRubyObject n) { final int days = n.convertToInteger().getIntValue(); if (n instanceof RubyRational) { if (((RubyRational) n).getDenominator().getLongValue() != 1) { return days + 1; // MRI rulez: 1/2 -> 1 (but 0.5 -> 0) } } return days; }
public static IRubyObject setpriority(Ruby runtime, IRubyObject arg1, IRubyObject arg2, IRubyObject arg3) { int which = (int)arg1.convertToInteger().getLongValue(); int who = (int)arg2.convertToInteger().getLongValue(); int prio = (int)arg3.convertToInteger().getLongValue(); runtime.getPosix().errno(0); int result = checkErrno(runtime, runtime.getPosix().setpriority(which, who, prio)); return runtime.newFixnum(result); }
public static IRubyObject setpgid(Ruby runtime, IRubyObject arg1, IRubyObject arg2) { int pid = (int)arg1.convertToInteger().getLongValue(); int gid = (int)arg2.convertToInteger().getLongValue(); return runtime.newFixnum(checkErrno(runtime, runtime.getPosix().setpgid(pid, gid))); }
@JRubyMethod(name = "indentation=") public IRubyObject indentation_set(ThreadContext context, IRubyObject level) { // TODO: unclear if this affects a running emitter options.setIndent((int)level.convertToInteger().getLongValue()); return level; }
private static int simpleIntDiff(IRubyObject n) { final int days = n.convertToInteger().getIntValue(); if (n instanceof RubyRational) { if (((RubyRational) n).getDenominator().getLongValue() != 1) { return days + 1; // MRI rulez: 1/2 -> 1 (but 0.5 -> 0) } } return days; }
public static IRubyObject getpriority(Ruby runtime, IRubyObject arg1, IRubyObject arg2) { int which = (int)arg1.convertToInteger().getLongValue(); int who = (int)arg2.convertToInteger().getLongValue(); int result = checkErrno(runtime, runtime.getPosix().getpriority(which, who)); return runtime.newFixnum(result); }
public static IRubyObject setpgid(Ruby runtime, IRubyObject arg1, IRubyObject arg2) { int pid = (int)arg1.convertToInteger().getLongValue(); int gid = (int)arg2.convertToInteger().getLongValue(); return runtime.newFixnum(checkErrno(runtime, runtime.getPosix().setpgid(pid, gid))); }
@JRubyMethod(name = "hash") public RubyFixnum hash(ThreadContext context) { long hash = isExclusive ? 1 : 0; long h = hash; long v = invokedynamic(context, begin, MethodNames.HASH).convertToInteger().getLongValue(); hash ^= v << 1; v = invokedynamic(context, end, MethodNames.HASH).convertToInteger().getLongValue(); hash ^= v << 9; hash ^= h << 24; return getRuntime().newFixnum(hash); }
@JRubyMethod(required = 4) public IRubyObject initialize(ThreadContext context, IRubyObject[] args) { family = ProtocolFamily.valueOf(args[0].convertToInteger().getLongValue()); level = SocketLevel.valueOf(args[1].convertToInteger().getLongValue()); option = SocketOption.valueOf(args[2].convertToInteger().getLongValue()); data = args[3].convertToString().getByteList(); intData = Pack.unpackInt_i(ByteBuffer.wrap(data.bytes())); return context.nil; }
protected int write(CallSite write, ByteBuffer src) throws IOException { ByteList buffer; if (src.hasArray()) { buffer = new ByteList(src.array(), src.position(), src.remaining(), true); } else { buffer = new ByteList(src.remaining()); buffer.append(src, src.remaining()); } IRubyObject written = write.call(runtime.getCurrentContext(), io, io, RubyString.newStringLight(runtime, buffer)); return (int)written.convertToInteger().getLongValue(); }
@JRubyMethod(name = "gregorian_leap?", alias = "leap?", meta = true) public static IRubyObject gregorian_leap_p(ThreadContext context, IRubyObject self, IRubyObject year) { final RubyInteger y = year.convertToInteger(); return context.runtime.newBoolean(isGregorianLeap(y.getLongValue())); }