Conversion utilities.
There are 3 mechanisms for converting between types: *
For example, I have a RubyFixnum and I know I need a long I can just call `getValue()`. If I need an int and I know enough about it to not care about range I can call `asInt`. If I do need check range I can call `toInt(context, (RubyFixnum) value)` and it will make sure it is a valid int value. If I don't know for sure if it is even capable of being an int I will call `toInt(context, (IRubyObject) value)`.
The naming conventions will tend to be {resolvedType}?[As|To}{returnedType} where {resolvedType} is omitted when the convention is obvious (`long toLong(ThreadContext context, IRubyObject)`). Right now we have `RubyInteger toInteger(ThreadContext, IRubyObject)` which means making a Ruby Integer vs a Java boxed Integer. If we ever needed a Java Integer (narrator: we won't) we would have to break this convention and make `Integer toJavaInteger(ThreadContext, IRubyObject)`. There are no example of {resolvedType} in any conversion methods but this is reserved in case we have more naming conflicts due to overlapping names.
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public static RubyBoolean | Returns: the Ruby Booleanthe current thread context context, boolean the boolean value value)Create a Ruby Boolean from a java boolean. |
| public static RubyFixnum | Returns: the Ruby Fixnumthe current thread context context, long the long value value)Create a Ruby Fixnum from a java long. |
| public static RubyFixnum | Returns: the Ruby Fixnumthe current thread context context, int the int value value)Create a Ruby Fixnum from a java int. |
| public static RubyFloat | Returns: the Ruby Floatthe current thread context context, double the double value value)Create a Ruby Float from a java double. |
| public static RubyFloat | Returns: the Ruby Floatthe current thread context context, long the long value value)Create a Ruby Float from a java long. |
| public static RubyInteger | Returns: the resultthe current thread context context, double the double value value)Create some type of Ruby Integer from a java double |
| public static RubySymbol | Returns: the new RubyStringthe current thread context context, String the contents to become a symbol string)Creates a new RubySymbol from the provided java String. |
| public static RubySymbol | Returns: the new RubyStringthe current thread context context, ByteList the contents to become a symbol bytelist)Creates a new RubySymbol from the provided java String. |
| public static RubySymbol | Returns: the new RubySymbolthe current thread context context, RubyString the contents to become a symbol string)Creates a new RubySymbol from the provided java String. |
| public static RubyArray | Returns: the value as a RubyArraythe current thread context context, IRubyObject the value to cast newValue)Cast the given value to a RubyArray with most basic typeError thrown if the value is not a RubyArray. |
| public static RubyArray | Returns: the value as a RubyArraythe current thread context context, IRubyObject the value to cast newValue, String the message to include in the type error message)Cast the given value to a RubyArray with most basic typeError thrown if the value is not a RubyArray. |
| public static RubyBignum | Returns: the value as a RubyBignumthe current thread context context, IRubyObject the value to cast newValue)Cast the given value to a RubyBignum with most basic typeError thrown if the value is not a RubyBignum. |
| public static RubyClass | Returns: the value as a RubyClassthe current thread context context, IRubyObject the value to cast newValue)Cast the given value to a RubyClass with most basic typeError thrown if the value is not a RubyClass. |
| public static RubyFile | Returns: the value as a RubyFilethe current thread context context, IRubyObject the value to cast newValue)Cast the given value to a RubyFile with most basic typeError thrown if the value is not a RubyFile. |
| public static RubyFixnum | Returns: the value as a RubyFixnumthe current thread context context, IRubyObject the value to cast newValue)Cast the given value to a RubyFixnum with most basic typeError thrown if the value is not a RubyFixnum. |
| public static RubyFixnum | Returns: the value as a RubyFixnumthe current thread context context, IRubyObject the value to cast newValue, String the message to include in the type error message)Cast the given value to a RubyFixnum with most basic typeError thrown if the value is not a RubyFixnum. |
| public static RubyHash | Returns: the value as a RubyHashthe current thread context context, IRubyObject the value to cast newValue)Cast the given value to a RubyHash with most basic typeError thrown if the value is not a RubyHash. |
| public static RubyHash | Returns: the value as a RubyHashthe current thread context context, IRubyObject the value to cast newValue, String the message to include in the type error message)Cast the given value to a RubyHash with most basic typeError thrown if the value is not a RubyHash. |
| public static RubyInteger | Returns: the value as a RubyIntegerthe current thread context context, IRubyObject the value to cast newValue)Cast the given value to a RubyInteger with most basic typeError thrown if the value is not a RubyInteger. |
| public static RubyInteger | Returns: the value as a RubyIntegerthe current thread context context, IRubyObject the value to cast newValue, String the message to include in the type error message)Cast the given value to a RubyInteger with most basic typeError thrown if the value is not a RubyInteger. |
| public static RubyModule | Returns: the value as a RubyModulethe current thread context context, IRubyObject the value to cast newValue)Cast the given value to a RubyModule with most basic typeError thrown if the value is not a RubyModule. |
| public static RubyModule | Returns: the value as a RubyModulethe current thread context context, IRubyObject the value to cast newValue, String the message to include in the type error message)Cast the given value to a RubyModule with most basic typeError thrown if the value is not a RubyModule. |
| public static RubyNumeric | Returns: the value as a RubyNumericthe current thread context context, IRubyObject the value to cast newValue, String the message to include in the type error message)Cast the given value to a RubyNumeric with most basic typeError thrown if the value is not a RubyNumeric. |
| public static RubyProc | Returns: the value as a RubyProcthe current thread context context, IRubyObject the value to cast newValue)Cast the given value to a RubyProc with most basic typeError thrown if the value is not a RubyProc. |
| public static RubyProc | Returns: the value as a RubyProcthe current thread context context, IRubyObject the value to cast newValue, String the message to include in the type error message)Cast the given value to a RubyProc with most basic typeError thrown if the value is not a RubyProc. |
| public static RubyRange | Returns: the value as a RubyRangethe current thread context context, IRubyObject the value to cast newValue)Cast the given value to a RubyRange with most basic typeError thrown if the value is not a RubyRange. |
| public static RubyString | Returns: the value as a RubyStringthe current thread context context, IRubyObject the value to cast newValue)Cast the given value to a RubyString with most basic typeError thrown if the value is not a RubyString. |
| public static RubySymbol | Returns: the value as a RubySymbolthe current thread context context, IRubyObject the value to cast newValue)Cast the given value to a RubySymbol with most basic typeError thrown if the value is not a RubySymbol. |
| public static int | Returns: the int valuethe current thread context context, long the long to check num)Check to make sure the long num given will fit into an int. |
| public static IRubyObject | Returns: the integer value or nil if the object or conversion is not an Integer.the current thread context context, IRubyObject the object to be converted obj)Check whether the given object is an Integer or can be converted to an Integer using #to_int. |
| public static IRubyObject | Returns: a Rational based on the object, or nil if it could not be convertedthe current thread context context, IRubyObject the object to convert obj)Convert the given argument to a Rational, or return nil if it cannot be converted. |
| public static IRubyObject | Returns: the String value or nil if the object or conversion is not a String.the current thread context context, IRubyObject the object to be converted obj)Check whether the given object is a String or can be converted to a String using #to_str. |
| public static byte | |
| public static double | Returns: the valuethe current thread context context, IRubyObject the Object to convert arg)Safely convert a Ruby Numeric into a java double value. |
| public static int | Returns: the int valuethe current thread context context, IRubyObject the RubyNumeric to convert arg)Safely convert a Ruby Numeric into a java long value. |
| public static long | |
| public static int | |
| public static RubyInteger | Returns: the int valuethe current thread context context, IRubyObject the RubyNumeric to convert arg)Safely convert a Ruby Numeric into a java long value. |
| private static long | |
| public static long | Returns: the valuethe current thread context context, IRubyObject the RubyNumeric to convert arg)Safely convert a Ruby Numeric into a java long value. |
| public static long | |
| public static long | |
| private static long | |
| public static RubySymbol | Returns: the new RubySymbolthe current thread context context, IRubyObject the object to convert to a symbol arg)Convert the given object to a Symbol, possibly calling to_str in the process. |
| Convert | back to summary |
|---|---|
| public Convert() | |
| asBoolean | back to summary |
|---|---|
| public static RubyBoolean asBoolean(ThreadContext context, boolean value) Create a Ruby Boolean from a java boolean.
| |
| asFixnum | back to summary |
|---|---|
| public static RubyFixnum asFixnum(ThreadContext context, long value) Create a Ruby Fixnum from a java long.
| |
| asFixnum | back to summary |
|---|---|
| public static RubyFixnum asFixnum(ThreadContext context, int value) Create a Ruby Fixnum from a java int.
| |
| asFloat | back to summary |
|---|---|
| public static RubyFloat asFloat(ThreadContext context, double value) Create a Ruby Float from a java double.
| |
| asFloat | back to summary |
|---|---|
| public static RubyFloat asFloat(ThreadContext context, long value) Create a Ruby Float from a java long.
| |
| asInteger | back to summary |
|---|---|
| public static RubyInteger asInteger(ThreadContext context, double value) Create some type of Ruby Integer from a java double
| |
| asSymbol | back to summary |
|---|---|
| public static RubySymbol asSymbol(ThreadContext context, String string) Creates a new RubySymbol from the provided java String.
| |
| asSymbol | back to summary |
|---|---|
| public static RubySymbol asSymbol(ThreadContext context, ByteList bytelist) Creates a new RubySymbol from the provided java String.
| |
| asSymbol | back to summary |
|---|---|
| public static RubySymbol asSymbol(ThreadContext context, RubyString string) Creates a new RubySymbol from the provided java String.
| |
| castAsArray | back to summary |
|---|---|
| public static RubyArray Cast the given value to a RubyArray with most basic typeError thrown if the value is not a RubyArray.
| |
| castAsArray | back to summary |
|---|---|
| public static RubyArray Cast the given value to a RubyArray with most basic typeError thrown if the value is not a RubyArray. Note if message is constructed you will pay that contruction cost. Manually cast to avoid that overhead in that case.
| |
| castAsBignum | back to summary |
|---|---|
| public static RubyBignum castAsBignum(ThreadContext context, IRubyObject newValue) Cast the given value to a RubyBignum with most basic typeError thrown if the value is not a RubyBignum.
| |
| castAsClass | back to summary |
|---|---|
| public static RubyClass castAsClass(ThreadContext context, IRubyObject newValue) Cast the given value to a RubyClass with most basic typeError thrown if the value is not a RubyClass.
| |
| castAsFile | back to summary |
|---|---|
| public static RubyFile castAsFile(ThreadContext context, IRubyObject newValue) Cast the given value to a RubyFile with most basic typeError thrown if the value is not a RubyFile.
| |
| castAsFixnum | back to summary |
|---|---|
| public static RubyFixnum castAsFixnum(ThreadContext context, IRubyObject newValue) Cast the given value to a RubyFixnum with most basic typeError thrown if the value is not a RubyFixnum.
| |
| castAsFixnum | back to summary |
|---|---|
| public static RubyFixnum castAsFixnum(ThreadContext context, IRubyObject newValue, String message) Cast the given value to a RubyFixnum with most basic typeError thrown if the value is not a RubyFixnum. Note if message is constructed you will pay that contruction cost. Manually cast to avoid that overhead in that case.
| |
| castAsHash | back to summary |
|---|---|
| public static RubyHash castAsHash(ThreadContext context, IRubyObject newValue) Cast the given value to a RubyHash with most basic typeError thrown if the value is not a RubyHash.
| |
| castAsHash | back to summary |
|---|---|
| public static RubyHash castAsHash(ThreadContext context, IRubyObject newValue, String message) Cast the given value to a RubyHash with most basic typeError thrown if the value is not a RubyHash. Note if message is constructed you will pay that contruction cost. Manually cast to avoid that overhead in that case.
| |
| castAsInteger | back to summary |
|---|---|
| public static RubyInteger castAsInteger(ThreadContext context, IRubyObject newValue) Cast the given value to a RubyInteger with most basic typeError thrown if the value is not a RubyInteger.
| |
| castAsInteger | back to summary |
|---|---|
| public static RubyInteger castAsInteger(ThreadContext context, IRubyObject newValue, String message) Cast the given value to a RubyInteger with most basic typeError thrown if the value is not a RubyInteger. Note if message is constructed you will pay that contruction cost. Manually cast to avoid that overhead in that case.
| |
| castAsModule | back to summary |
|---|---|
| public static RubyModule castAsModule(ThreadContext context, IRubyObject newValue) Cast the given value to a RubyModule with most basic typeError thrown if the value is not a RubyModule.
| |
| castAsModule | back to summary |
|---|---|
| public static RubyModule castAsModule(ThreadContext context, IRubyObject newValue, String message) Cast the given value to a RubyModule with most basic typeError thrown if the value is not a RubyModule. Note if message is constructed you will pay that contruction cost. Manually cast to avoid that overhead in that case.
| |
| castAsNumeric | back to summary |
|---|---|
| public static RubyNumeric castAsNumeric(ThreadContext context, IRubyObject newValue, String message) Cast the given value to a RubyNumeric with most basic typeError thrown if the value is not a RubyNumeric. Note if message is constructed you will pay that contruction cost. Manually cast to avoid that overhead in that case.
| |
| castAsProc | back to summary |
|---|---|
| public static RubyProc castAsProc(ThreadContext context, IRubyObject newValue) Cast the given value to a RubyProc with most basic typeError thrown if the value is not a RubyProc.
| |
| castAsProc | back to summary |
|---|---|
| public static RubyProc castAsProc(ThreadContext context, IRubyObject newValue, String message) Cast the given value to a RubyProc with most basic typeError thrown if the value is not a RubyProc. Note if message is constructed you will pay that contruction cost. Manually cast to avoid that overhead in that case.
| |
| castAsRange | back to summary |
|---|---|
| public static RubyRange castAsRange(ThreadContext context, IRubyObject newValue) Cast the given value to a RubyRange with most basic typeError thrown if the value is not a RubyRange.
| |
| castAsString | back to summary |
|---|---|
| public static RubyString castAsString(ThreadContext context, IRubyObject newValue) Cast the given value to a RubyString with most basic typeError thrown if the value is not a RubyString.
| |
| castAsSymbol | back to summary |
|---|---|
| public static RubySymbol castAsSymbol(ThreadContext context, IRubyObject newValue) Cast the given value to a RubySymbol with most basic typeError thrown if the value is not a RubySymbol.
| |
| checkInt | back to summary |
|---|---|
| public static int checkInt(ThreadContext context, long num) Check to make sure the long num given will fit into an int.
| |
| checkToInteger | back to summary |
|---|---|
| public static IRubyObject checkToInteger(ThreadContext context, IRubyObject obj) Check whether the given object is an Integer or can be converted to an Integer using #to_int.
| |
| checkToRational | back to summary |
|---|---|
| public static IRubyObject checkToRational(ThreadContext context, IRubyObject obj) Convert the given argument to a Rational, or return nil if it cannot be converted.
| |
| checkToString | back to summary |
|---|---|
| public static IRubyObject checkToString(ThreadContext context, IRubyObject obj) Check whether the given object is a String or can be converted to a String using #to_str.
| |
| toByte | back to summary |
|---|---|
| public static byte toByte(ThreadContext context, IRubyObject arg) | |
| toDouble | back to summary |
|---|---|
| public static double toDouble(ThreadContext context, IRubyObject arg) Safely convert a Ruby Numeric into a java double value. Raising if the value will not fit.
| |
| toInt | back to summary |
|---|---|
| public static int toInt(ThreadContext context, IRubyObject arg) Safely convert a Ruby Numeric into a java long value. Raising if the value will not fit.
| |
| toInt | back to summary |
|---|---|
| public static long toInt(ThreadContext context, RubyFloat value) | |
| toInt | back to summary |
|---|---|
| public static int toInt(ThreadContext context, RubyFixnum arg) | |
| toInteger | back to summary |
|---|---|
| public static RubyInteger toInteger(ThreadContext context, IRubyObject arg) Safely convert a Ruby Numeric into a java long value. Raising if the value will not fit.
| |
| toIntOther | back to summary |
|---|---|
| private static long toIntOther(ThreadContext context, IRubyObject arg) | |
| toLong | back to summary |
|---|---|
| public static long toLong(ThreadContext context, IRubyObject arg) Safely convert a Ruby Numeric into a java long value. Raising if the value will not fit.
| |
| toLong | back to summary |
|---|---|
| public static long toLong(ThreadContext context, RubyBignum value) | |
| toLong | back to summary |
|---|---|
| public static long toLong(ThreadContext context, RubyFloat value) | |
| toLongOther | back to summary |
|---|---|
| private static long toLongOther(ThreadContext context, IRubyObject arg) | |
| toSymbol | back to summary |
|---|---|
| public static RubySymbol toSymbol(ThreadContext context, IRubyObject arg) Convert the given object to a Symbol, possibly calling to_str in the process. MRI: rb_to_symbol
| |