Sha256: 78c5a2adf5ef7f277b683ee5bc85a0afc32c552c15abb6d6db02795d2b26a8b9
Contents?: true
Size: 662 Bytes
Versions: 4
Compression:
Stored size: 662 Bytes
Contents
module PyCall class IterableWrapper include Enumerable def initialize(obj) @obj = check_iterable(obj) end private def check_iterable(obj) unless PyCall.hasattr?(obj, :__iter__) raise ArgumentError, "%p object is not iterable" % obj end obj end def each return enum_for(__method__) unless block_given? iter = @obj.__iter__() while true begin yield iter.__next__() rescue PyCall::PyError => err if err.type == PyCall.builtins.StopIteration break else raise err end end end end end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
pycall-1.5.1 | lib/pycall/iterable_wrapper.rb |
pycall-1.5.0 | lib/pycall/iterable_wrapper.rb |
pycall-1.4.2 | lib/pycall/iterable_wrapper.rb |
pycall-1.4.1 | lib/pycall/iterable_wrapper.rb |