Class: Janeway::Interpreters::Yielder
- Inherits:
-
Object
- Object
- Janeway::Interpreters::Yielder
- Includes:
- IterationHelper
- Defined in:
- lib/janeway/interpreters/yielder.rb
Overview
Yields each input value.
This 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 Janeway.each method.
Constant Summary collapse
- EMPTY_RESULT =
Frozen empty array — Yielder is only used by Enumerator#each and #find_paths, both of which discard the traversal's return value (results are surfaced via yield instead). Returning a shared frozen array avoids allocating a wrapper array per leaf.
[].freeze
Constants included from IterationHelper
Instance Method Summary collapse
- #as_json ⇒ Hash
-
#initialize(&block) ⇒ Yielder
constructor
A new instance of Yielder.
-
#interpret(input, parent, _root, path) {|matched| ... } ⇒ Array
Yield each input value.
-
#next= ⇒ void
Dummy method from Interpreters::Base, allow child segment interpreter to disable the non-exist 'next' link.
Methods included from IterationHelper
#make_yield_proc, #normalized_path
Constructor Details
#initialize(&block) ⇒ Yielder
Returns a new instance of Yielder.
15 16 17 18 19 20 |
# File 'lib/janeway/interpreters/yielder.rb', line 15 def initialize(&block) @block = block # Make a proc that yields the correct number of values to a block @yield_proc = make_yield_proc(&block) end |
Instance Method Details
#as_json ⇒ Hash
47 48 49 |
# File 'lib/janeway/interpreters/yielder.rb', line 47 def as_json { type: self.class.to_s.split('::').last } end |
#interpret(input, parent, _root, path) {|matched| ... } ⇒ Array
Yield each input value
36 37 38 39 |
# File 'lib/janeway/interpreters/yielder.rb', line 36 def interpret(input, parent, _root, path) @yield_proc.call(input, parent, path) EMPTY_RESULT end |
#next= ⇒ void
This method returns an undefined value.
Dummy method from Interpreters::Base, allow child segment interpreter to disable the non-exist 'next' link.
44 |
# File 'lib/janeway/interpreters/yielder.rb', line 44 def next=(*); end |