Class: Janeway::Interpreters::Yielder
- Defined in:
- lib/janeway/interpreters/yielder.rb
Overview
Yields each input value. It is inserted at the end of the “real” selectors in the AST, to receive and yield the output. This is a supporting class for the supports the Janeway.each method.
This will get pushed onto the end of the query AST. Currently it must act like both an AST node and an interpreter. This will be simpler if TODO some day may the interpreter subclass methods can be merged into the AST classes
Constant Summary
Constants inherited from Base
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#initialize(&block) ⇒ Yielder
constructor
The implicit constructor forwards a closure to the base class constructor.
-
#interpret(input, _root) {|matched| ... } ⇒ Object
Yield each input value.
Constructor Details
#initialize(&block) ⇒ Yielder
The implicit constructor forwards a closure to the base class constructor. Base class constructor stores it in @node.
17 18 19 20 |
# File 'lib/janeway/interpreters/yielder.rb', line 17 def initialize(&block) super(Struct.new(:next).new) @block = block end |
Instance Method Details
#interpret(input, _root) {|matched| ... } ⇒ Object
Yield each input value
28 29 30 31 |
# File 'lib/janeway/interpreters/yielder.rb', line 28 def interpret(input, _root) @block.call(input) input.is_a?(Array) ? input : [input] end |