lib/pycall/list.rb in pycall-0.1.0.alpha.20170224 vs lib/pycall/list.rb in pycall-0.1.0.alpha.20170226

- old
+ new

@@ -1,8 +1,9 @@ module PyCall class List include PyObjectWrapper + include Enumerable def self.new(init=nil) case init when PyObject super @@ -45,10 +46,31 @@ LibPython.PyList_Size(__pyobj__) end def include?(value) value = Conversions.from_ruby(value) - LibPython.PyList_Contains(__pyobj__, value).to_ruby + value = LibPython.PySequence_Contains(__pyobj__, value) + raise PyError.fetch if value == -1 + 1 == value + end + + def ==(other) + case other + when Array + self.to_a == other + else + super + end + end + + def each + return enum_for unless block_given? + i, n = 0, size + while i < n + yield self[i] + i += 1 + end + self end def to_a [].tap do |a| i, n = 0, size