Method: RubyPython::Conversion.rtopObject
- Defined in:
- lib/rubypython/conversion.rb
.rtopObject(rObj, is_key = false) ⇒ Object
This will attempt to convert a Ruby object to an equivalent Python native type. Returns an FFI::Pointer to a Python object (the appropriate Py…Object C structure). If the conversion is unsuccessful, will raise UnsupportedConversion.
- rObj
-
A native Ruby object.
- is_key
-
Set to
trueif the provided Ruby object will be used as a key in a Pythondict. (This primarily matters for Array conversion.)
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
# File 'lib/rubypython/conversion.rb', line 125 def self.rtopObject(rObj, is_key = false) case rObj when String rtopString rObj when Array # If this object is going to be used as a hash key we should make it a # tuple instead of a list if is_key rtopArrayToTuple rObj else rtopArrayToList rObj end when Hash rtopHash rObj when Fixnum rtopFixnum rObj when Bignum rtopBignum rObj when Float rtopFloat rObj when true rtopTrue when false rtopFalse when Symbol rtopSymbol rObj when Proc, Method if RubyPython.legacy_mode raise UnsupportedConversion.new("Callbacks are not supported in Legacy Mode.") end rtopFunction rObj when Method rtopFunction rObj when nil rtopNone when RubyPython::PyObject rObj.pointer else raise UnsupportedConversion.new("Unsupported type #{rObj.class} for conversion.") end end |