Class: Melbourne::AST::If

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

Overview

An if statement as in:

a if true

Instance Attribute Summary collapse

Attributes inherited from Node

#line

Instance Method Summary collapse

Methods inherited from Node

#ascii_graph

Constructor Details

#initialize(line, condition, body, else_body) ⇒ If

Returns a new instance of If.



179
180
181
182
183
184
# File 'lib/melbourne/ast/control_flow.rb', line 179

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

Instance Attribute Details

#bodyObject

The body of the if statement (the code that is executed if the condition evaluates to true)



173
174
175
# File 'lib/melbourne/ast/control_flow.rb', line 173

def body
  @body
end

#conditionObject

The condition of the if statement



169
170
171
# File 'lib/melbourne/ast/control_flow.rb', line 169

def condition
  @condition
end

#elseObject

The else block of the if statement (if there is one)



177
178
179
# File 'lib/melbourne/ast/control_flow.rb', line 177

def else
  @else
end