Sha256: 1d974798d91bd274c654546b5fdd44602b362a44780dc341ec67681c7f0e508c

Contents?: true

Size: 856 Bytes

Versions: 9

Compression:

Stored size: 856 Bytes

Contents

module PyCall
  class Tuple
    include PyObjectWrapper

    def self.new(init)
      case init
      when Integer
        super(LibPython.PyTuple_New(init))
      when Array
        tuple = new(init.length)
        init.each_with_index do |obj, index|
          tuple[index] = obj
        end
        tuple
      when LibPython::PyObjectStruct
        super(init)
      end
    end

    # Make tuple from array
    def self.[](*ary)
      new(ary)
    end

    def size
      LibPython.PyTuple_Size(__pyobj__)
    end

    alias length size

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

    def []=(index, value)
      value = Conversions.from_ruby(value)
      LibPython.PyTuple_SetItem(__pyobj__, index, value)
    end

    def to_a
      Array.new(length) {|i| self[i] }
    end

    alias to_ary to_a
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
pycall-1.1.0.rc1 lib/pycall/tuple.rb
pycall-1.0.3 lib/pycall/tuple.rb
pycall-1.0.2-x86-mingw32 lib/pycall/tuple.rb
pycall-1.0.2-x64-mingw32 lib/pycall/tuple.rb
pycall-1.0.2 lib/pycall/tuple.rb
pycall-1.0.1-x86-mingw32 lib/pycall/tuple.rb
pycall-1.0.1-x64-mingw32 lib/pycall/tuple.rb
pycall-1.0.1 lib/pycall/tuple.rb
pycall-1.0.0 lib/pycall/tuple.rb