Class: MiniKraken::Core::DuckFiber
- Inherits:
-
Object
- Object
- MiniKraken::Core::DuckFiber
- Defined in:
- lib/mini_kraken/core/duck_fiber.rb
Overview
A mock class that mimicks the behavior of a Fiber instance. More specifically, it responds to ‘resume` message & returns a Context.
Instance Attribute Summary collapse
-
#callable ⇒ Proc, #call
readonly
The callable object to yield.
-
#state ⇒ Symbol
readonly
One of: :initial, :yielded.
Instance Method Summary collapse
-
#initialize(aCallable) ⇒ DuckFiber
constructor
Constructor.
-
#resume(*_args) ⇒ Core::Context, NilClass
Quacks like a Fiber object.
Constructor Details
#initialize(aCallable) ⇒ DuckFiber
Constructor.
18 19 20 21 |
# File 'lib/mini_kraken/core/duck_fiber.rb', line 18 def initialize(aCallable) @callable = valid_callable(aCallable) @state = :initial end |
Instance Attribute Details
#callable ⇒ Proc, #call (readonly)
Returns The callable object to yield.
11 12 13 |
# File 'lib/mini_kraken/core/duck_fiber.rb', line 11 def callable @callable end |
#state ⇒ Symbol (readonly)
Returns one of: :initial, :yielded.
14 15 16 |
# File 'lib/mini_kraken/core/duck_fiber.rb', line 14 def state @state end |
Instance Method Details
#resume(*_args) ⇒ Core::Context, NilClass
Quacks like a Fiber object. The first time, this method will return a Context objet. Subsequents calls just return nil (= no other solution available)
27 28 29 30 31 32 33 34 |
# File 'lib/mini_kraken/core/duck_fiber.rb', line 27 def resume(*_args) if state == :initial @state = :yielded return callable.call else return nil end end |