Class: Peruby::Op::ForEach
- Includes:
- LoopExecution
- Defined in:
- lib/peruby/op/loop.rb
Overview
Foreach loop with a fresh aliased lexical scalar each iteration.
Instance Method Summary collapse
-
#initialize(sigil, name, list, body, continuation = nil, label = nil) ⇒ ForEach
constructor
rubocop:disable Metrics/ParameterLists.
- #run(env, _context) ⇒ Object
Methods inherited from Base
#argument_cells, #local_slot, #lvalue, #run_subroutine, #to_callable, #warning_directive?
Constructor Details
#initialize(sigil, name, list, body, continuation = nil, label = nil) ⇒ ForEach
rubocop:disable Metrics/ParameterLists
88 89 90 91 92 93 94 95 |
# File 'lib/peruby/op/loop.rb', line 88 def initialize(sigil, name, list, body, continuation = nil, label = nil) # rubocop:disable Metrics/ParameterLists @sigil = sigil @name = name @list = list @body = body @continue = continuation @label = label end |
Instance Method Details
#run(env, _context) ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/peruby/op/loop.rb', line 97 def run(env, _context) @list.run(env, :list).each do |cell| keep_going = true env.with_scope do env.bind(@sigil, @name, cell) keep_going = run_iteration?(env) end break unless keep_going end nil end |