Class: Melbourne::AST::Case

Inherits:
Node
  • Object
show all
Defined in:
lib/melbourne/ast/control_flow.rb

Overview

A case statement as in

case
  when a == 1 then
    # something
  when a == 2
    # something
end

Direct Known Subclasses

ReceiverCase

Instance Attribute Summary collapse

Attributes inherited from Node

#line

Instance Method Summary collapse

Methods inherited from Node

#ascii_graph

Constructor Details

#initialize(line, whens, else_body) ⇒ Case

Returns a new instance of Case.



24
25
26
27
28
# File 'lib/melbourne/ast/control_flow.rb', line 24

def initialize(line, whens, else_body)
  @line = line
  @whens = whens
  @else = else_body || Nil.new(line)
end

Instance Attribute Details

#elseObject

The else node of the case statement (or nil if there is none)



22
23
24
# File 'lib/melbourne/ast/control_flow.rb', line 22

def else
  @else
end

#whensObject

The when nodes of the case statement



18
19
20
# File 'lib/melbourne/ast/control_flow.rb', line 18

def whens
  @whens
end