lib/pycall/conversion.rb in pycall-0.1.0.alpha.20170302 vs lib/pycall/conversion.rb in pycall-0.1.0.alpha.20170307

- old
+ new

@@ -6,12 +6,21 @@ def to_a [pytype, rbtype] end end + def self.each_type_pair + i, n = 1, @python_type_map.length + while i <= n + yield @python_type_map[n - i] + i += 1 + end + self + end + def self.python_type_mapping(pytype, rbtype) - @python_type_map.each_with_index do |type_pair, index| + each_type_pair do |type_pair| next unless pytype == type_pair.pytype type_pair.rbtype = rbtype return end @python_type_map << TypePair.new(pytype, rbtype) @@ -19,11 +28,11 @@ def self.to_ruby(pyobj) unless pyobj.kind_of? PyObject raise end - @python_type_map.each do |tp| + each_type_pair do |tp| pytype, rbtype = tp.to_a next unless pyobj.kind_of?(pytype) case when rbtype.kind_of?(Proc) return rbtype.(pyobj) @@ -59,10 +68,10 @@ when Symbol from_ruby(obj.to_s) when Array PyCall::List.new(obj).__pyobj__ else - LibPython.Py_None + PyCall.None end end def self.convert_to_boolean(py_obj) 0 != LibPython.PyInt_AsSsize_t(py_obj)