Class: Rubinius::AST::If

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

Instance Attribute Summary collapse

Attributes inherited from Node

#line

Instance Method Summary collapse

Methods inherited from Node

#ascii_graph, #attributes, #children, match_arguments?, match_send?, #new_block_generator, #new_generator, #node_name, node_name, #pos, #set_child, transform, #transform, transform_comment, transform_kind, transform_kind=, transform_name, #visit, #walk

Constructor Details

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

Returns a new instance of If.



138
139
140
141
142
143
# File 'lib/compiler/ast/control_flow.rb', line 138

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

Instance Attribute Details

#bodyObject

Returns the value of attribute body.



136
137
138
# File 'lib/compiler/ast/control_flow.rb', line 136

def body
  @body
end

#conditionObject

Returns the value of attribute condition.



136
137
138
# File 'lib/compiler/ast/control_flow.rb', line 136

def condition
  @condition
end

#elseObject

Returns the value of attribute else.



136
137
138
# File 'lib/compiler/ast/control_flow.rb', line 136

def else
  @else
end

Instance Method Details

#to_sexpObject



145
146
147
148
# File 'lib/compiler/ast/control_flow.rb', line 145

def to_sexp
  else_sexp = @else.kind_of?(NilLiteral) ? nil : @else.to_sexp
  [:if, @condition.to_sexp, @body.to_sexp, else_sexp]
end