Class: Twostroke::AST::ForLoop

Inherits:
Base
  • Object
show all
Defined in:
lib/twostroke/ast/for_loop.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#line

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from Twostroke::AST::Base

Instance Attribute Details

#bodyObject

Returns the value of attribute body.



3
4
5
# File 'lib/twostroke/ast/for_loop.rb', line 3

def body
  @body
end

#conditionObject

Returns the value of attribute condition.



3
4
5
# File 'lib/twostroke/ast/for_loop.rb', line 3

def condition
  @condition
end

#incrementObject

Returns the value of attribute increment.



3
4
5
# File 'lib/twostroke/ast/for_loop.rb', line 3

def increment
  @increment
end

#initializerObject

Returns the value of attribute initializer.



3
4
5
# File 'lib/twostroke/ast/for_loop.rb', line 3

def initializer
  @initializer
end

Instance Method Details

#collapseObject



5
6
7
8
9
10
# File 'lib/twostroke/ast/for_loop.rb', line 5

def collapse
  self.class.new initializer: initializer && initializer.collapse,
    condition: condition && condition.collapse,
    increment: increment && increment.collapse,
    body: body && body.collapse
end

#walk(&bk) ⇒ Object



12
13
14
15
16
17
18
19
# File 'lib/twostroke/ast/for_loop.rb', line 12

def walk(&bk)
  if yield self
    initializer.walk(&bk) if initializer
    condition.walk(&bk) if condition
    increment.walk(&bk) if increment
    body.walk &bk if body
  end
end