1234567891011121314151617181920212223 |
- class AST::ForLoop
- attr_reader :iterator, :iterable, :block
-
- def initialize(iterator, iterable, block)
- @iterator = iterator
- @iterable = iterable
- @block = block
- end
-
- def ==(other)
- other.is_a?(AST::ForLoop) && other.iterator == @iterator &&
- other.iterable == @iterable &&
- other.block == @block
- end
-
- def execute(env)
- @iterable.execute(env).each do |i|
- _env = Environment.new
- _env.set(@iterator.name, i)
- @block.statements.each { |statement| statement.execute(_env) }
- end
- end
- end
|