public static RubyNumeric toFloat(Ruby runtime, IRubyObject obj) { RubyClass floatClass = runtime.getFloat(); if (floatClass.isInstance(obj)) return (RubyNumeric) obj; if (!runtime.getNumeric().isInstance(obj)) throw runtime.newTypeError(obj, "Float"); return (RubyNumeric) convertToType19(obj, floatClass, "to_f", true); } /**
public static RubyNumeric toFloat(Ruby runtime, IRubyObject obj) { RubyClass floatClass = runtime.getFloat(); if (floatClass.isInstance(obj)) return (RubyNumeric) obj; if (!runtime.getNumeric().isInstance(obj)) throw runtime.newTypeError(obj, "Float"); return (RubyNumeric) convertToType19(obj, floatClass, "to_f", true); } /**
@Deprecated public static IRubyObject convertToType(IRubyObject obj, RubyClass target, int convertMethodIndex, String convertMethod) { if (target.isInstance(obj)) return obj; IRubyObject val = convertToType(obj, target, convertMethod, true); if (!target.isInstance(val)) { Ruby runtime = obj.getRuntime(); throw runtime.newTypeError(str(runtime, types(runtime, obj.getMetaClass()), "#" + convertMethod + " should return ", types(runtime, target))); } return val; }
@Deprecated public static IRubyObject convertToTypeWithCheck(IRubyObject obj, RubyClass target, int convertMethodIndex, String convertMethod) { if (target.isInstance(obj)) return obj; IRubyObject val = TypeConverter.convertToType(obj, target, convertMethod, false); if (val.isNil()) return val; if (!target.isInstance(val)) { Ruby runtime = obj.getRuntime(); throw runtime.newTypeError(str(runtime, types(runtime, obj.getMetaClass()), "#" + convertMethod + " should return ", types(runtime, target))); } return val; }
@Deprecated public static IRubyObject convertToTypeWithCheck(IRubyObject obj, RubyClass target, int convertMethodIndex, String convertMethod) { if (target.isInstance(obj)) return obj; IRubyObject val = TypeConverter.convertToType(obj, target, convertMethod, false); if (val.isNil()) return val; if (!target.isInstance(val)) { Ruby runtime = obj.getRuntime(); throw runtime.newTypeError(str(runtime, types(runtime, obj.getMetaClass()), "#" + convertMethod + " should return ", types(runtime, target))); } return val; }
private boolean requiresBacktrace(ThreadContext context) { IRubyObject debugMode; // We can only omit backtraces of descendents of Standard error for 'foo rescue nil' return context.exceptionRequiresBacktrace || ((debugMode = context.runtime.getGlobalVariables().get("$DEBUG")) != null && debugMode.isTrue()) || ! context.runtime.getStandardError().isInstance(exception); }
private boolean requiresBacktrace(ThreadContext context) { IRubyObject debugMode; // We can only omit backtraces of descendents of Standard error for 'foo rescue nil' return context.exceptionRequiresBacktrace || ((debugMode = context.runtime.getGlobalVariables().get("$DEBUG")) != null && debugMode.isTrue()) || ! context.runtime.getStandardError().isInstance(exception); }
public static IRubyObject isExceptionHandled(IRubyObject currentException, IRubyObject exception, ThreadContext context) { Ruby runtime = context.runtime; if (!runtime.getModule().isInstance(exception)) { throw runtime.newTypeError("class or module required for rescue clause"); } IRubyObject result = invoke(context, exception, "===", currentException); if (result.isTrue()) return result; return runtime.getFalse(); }
public static IRubyObject isExceptionHandled(IRubyObject currentException, IRubyObject exception, ThreadContext context) { Ruby runtime = context.runtime; if (!runtime.getModule().isInstance(exception)) { throw runtime.newTypeError("class or module required for rescue clause"); } IRubyObject result = invoke(context, exception, "===", currentException); if (result.isTrue()) return result; return runtime.getFalse(); }
public static IRubyObject isExceptionHandled(IRubyObject currentException, IRubyObject exception, ThreadContext context) { Ruby runtime = context.runtime; if (!runtime.getModule().isInstance(exception)) { throw runtime.newTypeError("class or module required for rescue clause"); } IRubyObject result = invoke(context, exception, "===", currentException); if (result.isTrue()) return result; return runtime.getFalse(); }
public static IRubyObject isExceptionHandled(IRubyObject currentException, IRubyObject exception, ThreadContext context) { Ruby runtime = context.runtime; if (!runtime.getModule().isInstance(exception)) { throw runtime.newTypeError("class or module required for rescue clause"); } IRubyObject result = invoke(context, exception, "===", currentException); if (result.isTrue()) return result; return runtime.getFalse(); }
@JRubyMethod(name = "to_native") public IRubyObject to_native(ThreadContext context, IRubyObject value, IRubyObject ctx) { if (value instanceof Struct && structClass.isInstance(value)) { return ((Struct) value).getMemory(); } else if (value.isNil()) { return Pointer.getNull(context.runtime); } else { throw context.runtime.newTypeError(value, structClass); } }
@JRubyMethod(name = "to_native") public IRubyObject to_native(ThreadContext context, IRubyObject value, IRubyObject ctx) { if (value instanceof Struct && structClass.isInstance(value)) { return ((Struct) value).getMemory(); } else if (value.isNil()) { return Pointer.getNull(context.runtime); } else { throw context.runtime.newTypeError(value, structClass); } }
public static String getLocalJumpTypeOrRethrow(RaiseException re) { RubyException exception = re.getException(); Ruby runtime = exception.getRuntime(); if (runtime.getLocalJumpError().isInstance(exception)) { RubyLocalJumpError jumpError = (RubyLocalJumpError)re.getException(); IRubyObject reason = jumpError.reason(); return reason.asJavaString(); } throw re; }
public static String getLocalJumpTypeOrRethrow(RaiseException re) { RubyException exception = re.getException(); Ruby runtime = exception.getRuntime(); if (runtime.getLocalJumpError().isInstance(exception)) { RubyLocalJumpError jumpError = (RubyLocalJumpError)re.getException(); IRubyObject reason = jumpError.reason(); return reason.asJavaString(); } throw re; }
public static String getLocalJumpTypeOrRethrow(RaiseException re) { RubyException exception = re.getException(); Ruby runtime = exception.getRuntime(); if (runtime.getLocalJumpError().isInstance(exception)) { RubyLocalJumpError jumpError = (RubyLocalJumpError)re.getException(); IRubyObject reason = jumpError.reason(); return reason.asJavaString(); } throw re; }
@Override public IRubyObject set(IRubyObject value) { if (!value.isNil() && !runtime.getException().isInstance(value) && !(JavaUtil.isJavaObject(value) && JavaUtil.unwrapJavaObject(value) instanceof Throwable)) { throw runtime.newTypeError("assigning non-exception to $!"); } return runtime.getCurrentContext().setErrorInfo(value); }
@Override public boolean isInstance(IRubyObject object) { if (!super.isInstance(object)) { return false; } RubyArray array = (RubyArray) object; boolean ret = array.size() == 2 && object.getRuntime().getArray().isInstance((IRubyObject) array.get(0)) && (null == array.get(1) || LIST_ITEM_CLASS.isInstance((IRubyObject) array.get(1))); return ret; }
private static RubyFloat needFloat(IRubyObject x) { if (x instanceof RubyFloat) { return (RubyFloat)x; } if (!x.getRuntime().getNumeric().isInstance(x)) { TypeConverter.handleUncoercibleObject(true, x, x.getRuntime().getFloat()); } return (RubyFloat) TypeConverter.convertToType19(x, x.getRuntime().getFloat(), "to_f", true); }
private static RubyFloat needFloat(IRubyObject x) { if (x instanceof RubyFloat) { return (RubyFloat)x; } if (!x.getRuntime().getNumeric().isInstance(x)) { TypeConverter.handleUncoercibleObject(true, x, x.getRuntime().getFloat()); } return (RubyFloat) TypeConverter.convertToType19(x, x.getRuntime().getFloat(), "to_f", true); }