private int getExpiry(IRubyObject[] args) { if (args.length > 2) { return (int) args[2].convertToInteger().getLongValue(); } return ttl; }
@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; }
@Deprecated // NOTE: should go away once no date.rb is using it @JRubyMethod(name = "_valid_weeknum?", meta = true, required = 4, optional = 1, visibility = Visibility.PRIVATE) public static IRubyObject _valid_weeknum_p(ThreadContext context, IRubyObject self, IRubyObject[] args) { final long sg = args.length > 4 ? val2sg(context, args[4]) : GREGORIAN; final int y = args[0].convertToInteger().getIntValue(); final int w = args[1].convertToInteger().getIntValue(); final int d = args[2].convertToInteger().getIntValue(); final int f = args[3].convertToInteger().getIntValue(); final Long jd = DateUtils._valid_weeknum_p(y, w, d, f, sg); return jd == null ? context.nil : RubyFixnum.newFixnum(context.runtime, jd); }
private static long other2long(IRubyObject arg) throws RaiseException { if (arg instanceof RubyFloat) return float2long((RubyFloat) arg); if (arg instanceof RubyBignum) return RubyBignum.big2long((RubyBignum) arg); if (arg.isNil()) { throw arg.getRuntime().newTypeError("no implicit conversion from nil to integer"); } return arg.convertToInteger().getLongValue(); }
@JRubyMethod public IRubyObject ungetbyte(IRubyObject b) { if (b.isNil()) return b; try { bufferedStream.unread(b.convertToInteger().getIntValue()); position--; } catch (IOException ioe) { throw getRuntime().newIOErrorFromException(ioe); } return getRuntime().getNil(); }
@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 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; } }
@Deprecated // NOTE: should go away once no date.rb is using it @JRubyMethod(name = "_valid_weeknum?", meta = true, required = 4, optional = 1, visibility = Visibility.PRIVATE) public static IRubyObject _valid_weeknum_p(ThreadContext context, IRubyObject self, IRubyObject[] args) { final long sg = args.length > 4 ? val2sg(context, args[4]) : GREGORIAN; final int y = args[0].convertToInteger().getIntValue(); final int w = args[1].convertToInteger().getIntValue(); final int d = args[2].convertToInteger().getIntValue(); final int f = args[3].convertToInteger().getIntValue(); final Long jd = DateUtils._valid_weeknum_p(y, w, d, f, sg); return jd == null ? context.nil : RubyFixnum.newFixnum(context.runtime, jd); }
private static long other2long(IRubyObject arg) throws RaiseException { if (arg.isNil()) { throw arg.getRuntime().newTypeError("no implicit conversion from nil to integer"); } else if (arg instanceof RubyFloat) { return float2long((RubyFloat)arg); } else if (arg instanceof RubyBignum) { return RubyBignum.big2long((RubyBignum) arg); } return arg.convertToInteger().getLongValue(); }
@JRubyMethod public IRubyObject ungetbyte(IRubyObject b) { if (b.isNil()) return b; try { bufferedStream.unread(b.convertToInteger().getIntValue()); position--; } catch (IOException ioe) { throw getRuntime().newIOErrorFromException(ioe); } return getRuntime().getNil(); }
@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 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(); }
@JRubyMethod(name = { "first", "ruby_first" }) // #first ext like with array: [1, 2, 3].first(2) == [1, 2] public static IRubyObject first(final ThreadContext context, final IRubyObject self, final IRubyObject count) { final java.util.List list = unwrapIfJavaObject(self); int len = count.convertToInteger().getIntValue(); int size = list.size(); if ( len > size ) len = size; return Java.getInstance(context.runtime, list.subList(0, len)); }
private static long other2long(IRubyObject arg) throws RaiseException { if (arg instanceof RubyFloat) return float2long((RubyFloat) arg); if (arg instanceof RubyBignum) return RubyBignum.big2long((RubyBignum) arg); if (arg.isNil()) { throw arg.getRuntime().newTypeError("no implicit conversion from nil to integer"); } return arg.convertToInteger().getLongValue(); }
@JRubyMethod(name = "line_width=") public IRubyObject line_width_set(ThreadContext context, IRubyObject width) { options.setWidth((int)width.convertToInteger().getLongValue()); return width; }
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(); }
@JRubyMethod(name = { "last", "ruby_last" }) // #last ext like with array: [1, 2, 3].last(2) == [2, 3] public static IRubyObject last(final ThreadContext context, final IRubyObject self, final IRubyObject count) { final java.util.List list = unwrapIfJavaObject(self); int len = count.convertToInteger().getIntValue(); int size = list.size(); int start = size - len; if ( start < 0 ) start = 0; int end = start + len; if ( end > size ) end = size; return Java.getInstance(context.runtime, list.subList(start, end)); }
private static long other2long(IRubyObject arg) throws RaiseException { if (arg.isNil()) { throw arg.getRuntime().newTypeError("no implicit conversion from nil to integer"); } else if (arg instanceof RubyFloat) { return float2long((RubyFloat)arg); } else if (arg instanceof RubyBignum) { return RubyBignum.big2long((RubyBignum) arg); } return arg.convertToInteger().getLongValue(); }
@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; }
@Override public IRubyObject set(IRubyObject value) { int line = (int)value.convertToInteger().getLongValue(); runtime.setCurrentLine(line); return value; }