Class: Twostroke::AST::Switch

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

Instance Attribute Summary collapse

Attributes inherited from Base

#line

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Switch

Returns a new instance of Switch.



4
5
6
7
# File 'lib/twostroke/ast/switch.rb', line 4

def initialize(*args)
  @cases = []
  super *args
end

Instance Attribute Details

#casesObject

Returns the value of attribute cases.



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

def cases
  @cases
end

#expressionObject

Returns the value of attribute expression.



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

def expression
  @expression
end

Instance Method Details

#collapseObject



8
9
10
# File 'lib/twostroke/ast/switch.rb', line 8

def collapse
  self.class.new expression: expression.collapse, cases: cases.collect(&:collapse)
end

#walk(&bk) ⇒ Object



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

def walk(&bk)
  if yield self
    
    expression.walk &bk
    cases.each { |c| c.walk &bk }
  end
end