public static RubyArray asArray(ThreadContext context, IRubyObject value) { RubyClass array = context.runtime.getArray(); IRubyObject tmp = TypeConverter.convertToTypeWithCheck19(value, array, "to_ary"); if (tmp.isNil()) { tmp = TypeConverter.convertToTypeWithCheck19(value, array, "to_a"); if (tmp.isNil()) return context.runtime.newEmptyArray(); } return (RubyArray) tmp; // converters will guarantee it is RubyArray or raise. }
public static RubyArray asArray(ThreadContext context, IRubyObject value) { RubyClass array = context.runtime.getArray(); IRubyObject tmp = TypeConverter.convertToTypeWithCheck19(value, array, "to_ary"); if (tmp.isNil()) { tmp = TypeConverter.convertToTypeWithCheck19(value, array, "to_a"); if (tmp.isNil()) return context.runtime.newEmptyArray(); } return (RubyArray) tmp; // converters will guarantee it is RubyArray or raise. }
/** rb_check_string_type * * Tries to return a coerced string representation of this object, * using "to_str". If that returns something other than a String * or nil, an empty String will be returned. * */ public IRubyObject checkStringType19() { IRubyObject str = TypeConverter.convertToTypeWithCheck19(this, getRuntime().getString(), "to_str"); if(!str.isNil() && !(str instanceof RubyString)) { str = RubyString.newEmptyString(getRuntime()); } return str; }
/** rb_check_string_type * * Tries to return a coerced string representation of this object, * using "to_str". If that returns something other than a String * or nil, an empty String will be returned. * */ public IRubyObject checkStringType19() { IRubyObject str = TypeConverter.convertToTypeWithCheck19(this, getRuntime().getString(), "to_str"); if(!str.isNil() && !(str instanceof RubyString)) { str = RubyString.newEmptyString(getRuntime()); } return str; }
public static IRubyObject[] zipCommonConvert(Ruby runtime, IRubyObject[] args, String method) { RubyClass array = runtime.getArray(); ThreadContext context = runtime.getCurrentContext(); // 1.9 tries to convert, and failing that tries to "each" elements into a new array if (runtime.is1_9()) { for (int i = 0; i < args.length; i++) { IRubyObject result = TypeConverter.convertToTypeWithCheck19(args[i], array, method); if (result.isNil()) { result = takeItems(context, args[i]); } args[i] = result; } } else { for (int i = 0; i < args.length; i++) { args[i] = TypeConverter.convertToType(args[i], array, method); } } return args; }
public static IRubyObject[] zipCommonConvert(Ruby runtime, IRubyObject[] args, String method) { RubyClass array = runtime.getArray(); ThreadContext context = runtime.getCurrentContext(); // 1.9 tries to convert, and failing that tries to "each" elements into a new array if (runtime.is1_9()) { for (int i = 0; i < args.length; i++) { IRubyObject result = TypeConverter.convertToTypeWithCheck19(args[i], array, method); if (result.isNil()) { result = takeItems(context, args[i]); } args[i] = result; } } else { for (int i = 0; i < args.length; i++) { args[i] = TypeConverter.convertToType(args[i], array, method); } } return args; }