public static IRubyObject checkHashType(Ruby runtime, IRubyObject obj) { if (obj instanceof RubyHash) return obj; return TypeConverter.convertToTypeWithCheck(obj, runtime.getHash(), "to_hash"); }
public static IRubyObject checkStringType(Ruby runtime, IRubyObject obj) { if (obj instanceof RubyString) return obj; return TypeConverter.convertToTypeWithCheck(obj, runtime.getString(), "to_str"); }
public static IRubyObject checkIntegerType(ThreadContext context, IRubyObject obj) { if (obj instanceof RubyFixnum) return obj; TypeConverterSites sites = sites(context); IRubyObject conv = convertToTypeWithCheck(context, obj, context.runtime.getInteger(), sites.to_int_checked); return conv instanceof RubyInteger ? conv : context.nil; }
/** rb_check_array_type * * Returns the result of trying to convert this object to an Array * with "to_ary". */ public IRubyObject checkArrayType() { return TypeConverter.convertToTypeWithCheck(this, getRuntime().getArray(), "to_ary"); }
public static IRubyObject checkFloatType(Ruby runtime, IRubyObject obj) { if (obj instanceof RubyFloat) return obj; if (!(obj instanceof RubyNumeric)) return runtime.getNil(); return TypeConverter.convertToTypeWithCheck(obj, runtime.getFloat(), "to_f"); }
@JRubyMethod(name = "try_convert", meta = true) public static IRubyObject try_convert(ThreadContext context, IRubyObject recv, IRubyObject args) { return TypeConverter.convertToTypeWithCheck(args, context.runtime.getHash(), "to_hash"); }
public static IRubyObject checkFloatType(Ruby runtime, IRubyObject obj) { if (obj instanceof RubyFloat) return obj; ThreadContext context = runtime.getCurrentContext(); TypeConverterSites sites = sites(context); return TypeConverter.convertToTypeWithCheck(context, obj, runtime.getFloat(), sites.to_f_checked); }
public static IRubyObject checkFloatType(Ruby runtime, IRubyObject obj) { if (obj instanceof RubyFloat) return obj; ThreadContext context = runtime.getCurrentContext(); TypeConverterSites sites = sites(context); return TypeConverter.convertToTypeWithCheck(context, obj, runtime.getFloat(), sites.to_f_checked); }
public static RubyArray rb_Array(ThreadContext context, IRubyObject val) { IRubyObject tmp = checkArrayType(context, val); // to_ary if (tmp == context.nil) { TypeConverterSites sites = sites(context); tmp = convertToTypeWithCheck(context, val, context.runtime.getArray(), sites.to_a_checked); if (tmp == context.nil) { return context.runtime.newArray(val); } } return (RubyArray) tmp; }
public static RubyArray rb_Array(ThreadContext context, IRubyObject val) { IRubyObject tmp = checkArrayType(context, val); // to_ary if (tmp == context.nil) { TypeConverterSites sites = sites(context); tmp = convertToTypeWithCheck(context, val, context.runtime.getArray(), sites.to_a_checked); if (tmp == context.nil) { return context.runtime.newArray(val); } } return (RubyArray) tmp; }
public static IRubyObject checkStringType(IRubyObject self) { IRubyObject str = TypeConverter.convertToTypeWithCheck(self, getRuntime(self).getString(), "to_str"); if(!str.isNil() && !(str instanceof RubyString)) { str = RubyString.newEmptyString(getRuntime(self)); } return str; }
public static IRubyObject checkStringType(IRubyObject self) { IRubyObject str = TypeConverter.convertToTypeWithCheck(self, getRuntime(self).getString(), "to_str"); if(!str.isNil() && !(str instanceof RubyString)) { str = RubyString.newEmptyString(getRuntime(self)); } return str; }
@JRubyMethod(name = "reopen", required = 1, optional = 1) public IRubyObject reopen(ThreadContext context, IRubyObject[] args) { Ruby runtime = context.runtime; IRubyObject tmp = TypeConverter.convertToTypeWithCheck(args[0], runtime.getIO(), "to_io"); if (!tmp.isNil()) { reopenIO(runtime, (RubyIO) tmp); } else { reopenPath(runtime, args); } return this; }
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 = "reopen", required = 1, optional = 1) public IRubyObject reopen(ThreadContext context, IRubyObject[] args) { Ruby runtime = context.runtime; IRubyObject tmp = TypeConverter.convertToTypeWithCheck(args[0], runtime.getIO(), "to_io"); if (!tmp.isNil()) { reopenIO(runtime, (RubyIO) tmp); } else { reopenPath(runtime, args); } return this; }
public static IRubyObject checkStringType(IRubyObject self) { IRubyObject str = TypeConverter.convertToTypeWithCheck(self, getRuntime(self).getString(), "to_str"); if(!str.isNil() && !(str instanceof RubyString)) { str = RubyString.newEmptyString(getRuntime(self)); } return str; }
@JIT public static RubyArray irSplat(ThreadContext context, IRubyObject ary) { Ruby runtime = context.runtime; IRubyObject tmp = TypeConverter.convertToTypeWithCheck(context, ary, runtime.getArray(), sites(context).to_a_checked); if (tmp.isNil()) { tmp = runtime.newArray(ary); } else if (true /**RTEST(flag)**/) { // this logic is only used for bare splat, and MRI dups tmp = ((RubyArray)tmp).aryDup(); } return (RubyArray)tmp; }
@JRubyMethod(name = "sub!", reads = BACKREF, writes = BACKREF) public IRubyObject sub_bang(ThreadContext context, IRubyObject arg0, IRubyObject arg1, Block block) { Ruby runtime = context.runtime; IRubyObject hash = TypeConverter.convertToTypeWithCheck(context, arg1, runtime.getHash(), sites(context).to_hash_checked); frozenCheck(); if (hash == context.nil) { return subBangNoIter(context, asRegexpArg(runtime, arg0), arg1.convertToString()); } return subBangIter(context, asRegexpArg(runtime, arg0), (RubyHash) hash, block); }
@JRubyMethod public static IRubyObject detect_implicit(IRubyObject self, IRubyObject val) { IRubyObject tmp = TypeConverter.convertToTypeWithCheck(val, self.getRuntime().getString(), "to_str"); if(!tmp.isNil()) { ByteList bl = ((RubyString)tmp).getByteList(); String type_id = ImplicitScanner2.matchImplicit(Pointer.create(bl.bytes, bl.begin), bl.realSize); return self.getRuntime().newString(type_id); } return RubyString.newEmptyString(self.getRuntime()); } }