Class: PyCall::List

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/pycall/list.rb

Instance Method Summary collapse

Instance Method Details

#<<(item) ⇒ Object



22
23
24
# File 'lib/pycall/list.rb', line 22

def <<(item)
  append(item)
end

#each(&block) ⇒ Object



16
17
18
19
20
# File 'lib/pycall/list.rb', line 16

def each(&block)
  return enum_for unless block_given?
  LibPython::Helpers.sequence_each(__pyptr__, &block)
  self
end

#include?(item) ⇒ Boolean

Returns:

  • (Boolean)


8
9
10
# File 'lib/pycall/list.rb', line 8

def include?(item)
  LibPython::Helpers.sequence_contains(__pyptr__, item)
end

#lengthObject



12
13
14
# File 'lib/pycall/list.rb', line 12

def length
  PyCall.len(self)
end

#push(*items) ⇒ Object



26
27
28
# File 'lib/pycall/list.rb', line 26

def push(*items)
  items.each {|i| append(i) }
end

#sortObject



30
31
32
# File 'lib/pycall/list.rb', line 30

def sort
  dup.sort!
end

#sort!Object



34
35
36
37
# File 'lib/pycall/list.rb', line 34

def sort!
  LibPython::Helpers.getattr(__pyptr__, :sort).__call__
  self
end

#to_aObject Also known as: to_ary



39
40
41
# File 'lib/pycall/list.rb', line 39

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