module PyCall::PyObjectWrapper

Constants

OPERATOR_METHOD_NAMES

Attributes

__pyptr__[R]

Public Class Methods

extend_object(obj) click to toggle source
Calls superclass method
# File lib/pycall/pyobject_wrapper.rb, line 7
def self.extend_object(obj)
  pyptr = obj.instance_variable_get(:@__pyptr__)
  unless pyptr.kind_of? PyPtr
    raise TypeError, "@__pyptr__ should have PyCall::PyPtr object"
  end
  super
end

Public Instance Methods

[](*key) click to toggle source
# File lib/pycall/pyobject_wrapper.rb, line 78
def [](*key)
  LibPython::Helpers.getitem(__pyptr__, key)
end
[]=(*key, value) click to toggle source
# File lib/pycall/pyobject_wrapper.rb, line 82
def []=(*key, value)
  LibPython::Helpers.setitem(__pyptr__, key, value)
end
call(*args) click to toggle source
# File lib/pycall/pyobject_wrapper.rb, line 86
def call(*args)
  LibPython::Helpers.call_object(__pyptr__, *args)
end
coerce(other) click to toggle source
# File lib/pycall/pyobject_wrapper.rb, line 142
def coerce(other)
  [SwappedOperationAdapter.new(other), self]
end
dup() click to toggle source
Calls superclass method
# File lib/pycall/pyobject_wrapper.rb, line 146
def dup
  super.tap do |duped|
    copied = PyCall.import_module('copy').copy(__pyptr__)
    copied = copied.__pyptr__ if copied.kind_of? PyObjectWrapper
    duped.instance_variable_set(:@__pyptr__, copied)
  end
end
inspect() click to toggle source
# File lib/pycall/pyobject_wrapper.rb, line 154
def inspect
  PyCall.builtins.repr(__pyptr__)
end
kind_of?(cls) click to toggle source
Calls superclass method
# File lib/pycall/pyobject_wrapper.rb, line 54
def kind_of?(cls)
  case cls
  when PyTypeObjectWrapper
    __pyptr__.kind_of?(cls.__pyptr__)
  else
    super
  end
end
method_missing(name, *args) click to toggle source
Calls superclass method
# File lib/pycall/pyobject_wrapper.rb, line 29
def method_missing(name, *args)
  name_str = name.to_s if name.kind_of?(Symbol)
  name_str.chop! if name_str.end_with?('=')
  case name
  when *OPERATOR_METHOD_NAMES.keys
    op_name = OPERATOR_METHOD_NAMES[name]
    if LibPython::Helpers.hasattr?(__pyptr__, op_name)
      LibPython::Helpers.define_wrapper_method(self, op_name)
      singleton_class.__send__(:alias_method, name, op_name)
      return self.__send__(name, *args)
    end
  else
    if LibPython::Helpers.hasattr?(__pyptr__, name_str)
      LibPython::Helpers.define_wrapper_method(self, name)
      return self.__send__(name, *args)
    end
  end
  super
end
respond_to_missing?(name, include_private) click to toggle source
Calls superclass method
# File lib/pycall/pyobject_wrapper.rb, line 49
def respond_to_missing?(name, include_private)
  return true if LibPython::Helpers.hasattr?(__pyptr__, name)
  super
end
to_f() click to toggle source
# File lib/pycall/pyobject_wrapper.rb, line 166
def to_f
  LibPython::Helpers.call_object(PyCall::builtins.float.__pyptr__, __pyptr__)
end
to_i() click to toggle source
# File lib/pycall/pyobject_wrapper.rb, line 162
def to_i
  LibPython::Helpers.call_object(PyCall::builtins.int.__pyptr__, __pyptr__)
end
to_s() click to toggle source
# File lib/pycall/pyobject_wrapper.rb, line 158
def to_s
  LibPython::Helpers.str(__pyptr__)
end