A toy dynamic programming language written in Ruby
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

for_loop.rb 495B

12345678910111213141516171819202122
  1. class AST::ForLoop
  2. attr_reader :iterator, :iterable, :block
  3. def initialize(iterator, iterable, block)
  4. @iterator = iterator
  5. @iterable = iterable
  6. @block = block
  7. end
  8. def ==(other)
  9. other.is_a?(AST::ForLoop) && other.iterator == @iterator &&
  10. other.iterable == @iterable && other.block == @block
  11. end
  12. def execute(env)
  13. @iterable.execute(env).each do |i|
  14. _env = Environment.new
  15. _env.set(@iterator.name, i)
  16. @block.execute(_env)
  17. end
  18. end
  19. end