Module: PyBind::PyObjectClassMethods
- Defined in:
- lib/pybind/wrapper.rb
Instance Method Summary collapse
- #from_python(pystruct) ⇒ Object
- #pybind_type(pytype, &block) ⇒ Object
- #python_instance?(pyobj) ⇒ Boolean
- #python_subclass?(pyobj) ⇒ Boolean
- #to_python_struct ⇒ Object (also: #python_type, #to_python)
Instance Method Details
#from_python(pystruct) ⇒ Object
29 30 31 |
# File 'lib/pybind/wrapper.rb', line 29 def from_python(pystruct) new(pystruct) end |
#pybind_type(pytype, &block) ⇒ Object
7 8 9 10 11 |
# File 'lib/pybind/wrapper.rb', line 7 def pybind_type(pytype, &block) raise ArgumentError, "#{self} is already bound with #{@pystruct}" if @pystruct define_singleton_method :from_python, &block if block @pystruct = pytype.to_python_struct end |
#python_instance?(pyobj) ⇒ Boolean
13 14 15 16 17 18 19 |
# File 'lib/pybind/wrapper.rb', line 13 def python_instance?(pyobj) return false unless @pystruct pystruct = pyobj.to_python_struct value = LibPython.PyObject_IsInstance(pystruct, @pystruct) raise PyError.fetch if value == -1 value == 1 end |
#python_subclass?(pyobj) ⇒ Boolean
21 22 23 24 25 26 27 |
# File 'lib/pybind/wrapper.rb', line 21 def python_subclass?(pyobj) return false unless @pystruct pystruct = pyobj.to_python_struct value = LibPython.PyObject_IsSubclass(pystruct, @pystruct) raise PyError.fetch if value == -1 value == 1 end |
#to_python_struct ⇒ Object Also known as: python_type, to_python
33 34 35 |
# File 'lib/pybind/wrapper.rb', line 33 def to_python_struct @pystruct end |