module PyBind::PyObjectWrapper
Public Class Methods
included(mod)
click to toggle source
# File lib/pybind/wrapper.rb, line 93 def self.included(mod) mod.extend(PyObjectClassMethods) Types.register_type(mod) end
new(pystruct)
click to toggle source
# File lib/pybind/wrapper.rb, line 52 def initialize(pystruct) raise TypeError, "the argument must be a PyObjectStruct" unless pystruct.kind_of? PyObjectStruct @pystruct = pystruct end
Public Instance Methods
autocall_method_missing(value, *args, **kwargs)
click to toggle source
# File lib/pybind/autocall.rb, line 5 def autocall_method_missing(value, *args, **kwargs) case value when PyCallable value.call(*args, **kwargs) else value end end
call(*args, **kwargs)
click to toggle source
# File lib/pybind/wrapper.rb, line 57 def call(*args, **kwargs) args = PyTuple[*args] kwargs = kwargs.empty? ? PyObject.null : PyDict.new(kwargs) res = LibPython.PyObject_Call(@pystruct, args.to_python_struct, kwargs.to_python_struct) raise PyError.fetch unless LibPython.PyErr_Occurred().null? res.to_ruby end
inspect()
click to toggle source
Calls superclass method
# File lib/pybind/wrapper.rb, line 71 def inspect str = LibPython.PyObject_Repr(@pystruct) return "#<#{self.class.name || python_type} #{str.to_ruby}>" unless str.null? super end
methods()
click to toggle source
# File lib/pybind/wrapper.rb, line 77 def methods LibPython.PyObject_Dir(@pystruct).to_ruby.map &:to_sym end
python_type()
click to toggle source
# File lib/pybind/wrapper.rb, line 84 def python_type LibPython.PyObject_Type(@pystruct).to_ruby end
to_python_struct()
click to toggle source
# File lib/pybind/wrapper.rb, line 88 def to_python_struct @pystruct end
Also aliased as: to_python
to_s()
click to toggle source
Calls superclass method
# File lib/pybind/wrapper.rb, line 65 def to_s str = LibPython.PyObject_Str(@pystruct) return str.to_ruby unless str.null? super end
Private Instance Methods
method_missing(name, *args, **kwargs)
click to toggle source
Calls superclass method
# File lib/pybind/wrapper.rb, line 100 def method_missing(name, *args, **kwargs) attr_name = name.to_s is_setter = attr_name.end_with?("=") attr_name = attr_name.chomp('=') if is_setter if has_attribute?(attr_name) if is_setter set_attribute(attr_name, *args) else autocall_method_missing(get_attribute(attr_name), *args, **kwargs) end else super end end