Method: RubyPython.generator
- Defined in:
- lib/rubypython/pygenerator.rb
.generator ⇒ Object
Creates a Ruby lambda that acts like a Python generator. Uses RubyPython.generator_type
and Fiber to work the generator as a coroutine.
Note: This method only exists in the RubyPython if the Fiber exists.
40 41 42 43 44 45 46 47 48 49 |
# File 'lib/rubypython/pygenerator.rb', line 40 def generator return lambda do |*args| fib = Fiber.new do yield *args Python.PyErr_SetNone(Python.PyExc_StopIteration) FFI::Pointer::NULL end generator_type.__call__(lambda { fib.resume }) end end |