Class: Twostroke::AST::Case

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

Instance Attribute Summary collapse

Attributes inherited from Base

#line

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Case

Returns a new instance of Case.



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

def initialize(*args)
  @statements = []
  @is_default = false
  super *args
end

Instance Attribute Details

#expressionObject

Returns the value of attribute expression.



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

def expression
  @expression
end

#statementsObject

Returns the value of attribute statements.



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

def statements
  @statements
end

Instance Method Details

#collapseObject



9
10
11
# File 'lib/twostroke/ast/case.rb', line 9

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

#walk(&bk) ⇒ Object



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

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