Class: PyBind::PyTuple

Inherits:
Object show all
Includes:
PyObjectWrapper, PySequence
Defined in:
lib/pybind/types/tuple.rb

Constant Summary

Constants included from Operator

Operator::BINARY_OPERATION_OPFUNCS, Operator::UNARY_OPERATION_OPFUNCS

Constants included from RichComparer

RichComparer::Py_EQ, RichComparer::Py_GE, RichComparer::Py_GT, RichComparer::Py_LE, RichComparer::Py_LT, RichComparer::Py_NE, RichComparer::RICH_COMPARISON_OPCODES

Class Method Summary collapse

Instance Method Summary collapse

Methods included from PySequence

#each, #include?, #to_a

Methods included from PyObjectWrapper

#autocall_method_missing, #call, included, #initialize, #inspect, #methods, #python_type, #to_python_struct, #to_s

Methods included from Operator

#!, #**, #<=>, #===, #__binary_operate__, #__unary_operate__

Methods included from RichComparer

#__rich_compare__

Methods included from AttrAccessor

#get_attribute, #has_attribute?, #remove_attribute, #set_attribute

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class PyBind::PyObjectWrapper

Class Method Details

.[](*ary) ⇒ Object

Make tuple from array



28
29
30
# File 'lib/pybind/types/tuple.rb', line 28

def self.[](*ary)
  new(ary)
end

.new(init) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/pybind/types/tuple.rb', line 10

def self.new(init)
  case init
  when PyObjectStruct
    super
  when Integer
    super(LibPython.PyTuple_New(init))
  when Array
    tuple = new(init.size)
    init.each_with_index do |obj, index|
      tuple[index] = obj
    end
    tuple
  else
    raise TypeError, "the argument must be an Integer, a PyObjectStruct or a Array"
  end
end

Instance Method Details

#[](index) ⇒ Object



36
37
38
# File 'lib/pybind/types/tuple.rb', line 36

def [](index)
  LibPython.PyTuple_GetItem(@pystruct, index).to_ruby
end

#[]=(index, value) ⇒ Object



40
41
42
43
# File 'lib/pybind/types/tuple.rb', line 40

def []=(index, value)
  value = value.to_python
  LibPython.PyTuple_SetItem(@pystruct, index, value)
end

#sizeObject



32
33
34
# File 'lib/pybind/types/tuple.rb', line 32

def size
  LibPython.PyTuple_Size(@pystruct)
end