Sha256: a3f7367f91f96333e8d448e0c1f80931d222cc9b6828bcddc7c7d522d599327a

Contents?: true

Size: 755 Bytes

Versions: 1

Compression:

Stored size: 755 Bytes

Contents

require 'pybind/types/sequence'

module PyBind
  class PyList
    include PyObjectWrapper
    pybind_type LibPython.PyList_Type

    include PySequence

    def self.new(init = nil)
      case init
      when PyObjectStruct
        super
      when nil
        new(0)
      when Integer
        new(LibPython.PyList_New(init))
      when Array
        new.tap do |list|
          init.each do |item|
            list << item
          end
        end
      else
        raise TypeError, "the argument must be an Integer, a PyObjectStruct or a Array"
      end
    end

    def <<(value)
      value = value.to_python
      LibPython.PyList_Append(@pystruct, value)
      self
    end

    def size
      LibPython.PyList_Size(@pystruct)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
pybind-0.1.0 lib/pybind/types/list.rb