Class: Estreet::ForStatement

Inherits:
Statement show all
Defined in:
lib/estreet/loops.rb

Instance Attribute Summary

Attributes inherited from Node

#source_location

Instance Method Summary collapse

Methods inherited from Statement

#<<, #to_statement

Methods inherited from Node

#as_json, #loc, #type

Constructor Details

#initialize(init, test, update, body) ⇒ ForStatement

Returns a new instance of ForStatement.

Raises:

  • (TypeError)


16
17
18
19
20
21
22
23
24
25
26
# File 'lib/estreet/loops.rb', line 16

def initialize(init, test, update, body)
  # TODO: respond_to to_declaration, maybe?
  raise TypeError unless init.is_a?(VariableDeclaration) ||
    init.is_a?(Expression) ||
    init.nil?

  @init = init if init
  @test = test.to_expression if test
  @update = update.to_expression if update
  @body = body.to_statement
end

Instance Method Details

#attributesObject



28
29
30
# File 'lib/estreet/loops.rb', line 28

def attributes
  super.merge(init: @init, test: @test, update: @update, body: @body)
end