Class: SyntaxTree::IfMod

Inherits:
Node
  • Object
show all
Defined in:
lib/syntax_tree/node.rb

Overview

IfMod represents the modifier form of an if statement.

expression if predicate

Instance Attribute Summary collapse

Attributes inherited from Node

#location

Instance Method Summary collapse

Methods inherited from Node

#construct_keys, #pretty_print, #to_json

Constructor Details

#initialize(statement:, predicate:, location:, comments: []) ⇒ IfMod

Returns a new instance of IfMod.



5599
5600
5601
5602
5603
5604
# File 'lib/syntax_tree/node.rb', line 5599

def initialize(statement:, predicate:, location:, comments: [])
  @statement = statement
  @predicate = predicate
  @location = location
  @comments = comments
end

Instance Attribute Details

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



5597
5598
5599
# File 'lib/syntax_tree/node.rb', line 5597

def comments
  @comments
end

#predicateObject (readonly)

untyped

the expression to be checked



5594
5595
5596
# File 'lib/syntax_tree/node.rb', line 5594

def predicate
  @predicate
end

#statementObject (readonly)

untyped

the expression to be executed



5591
5592
5593
# File 'lib/syntax_tree/node.rb', line 5591

def statement
  @statement
end

Instance Method Details

#accept(visitor) ⇒ Object



5606
5607
5608
# File 'lib/syntax_tree/node.rb', line 5606

def accept(visitor)
  visitor.visit_if_mod(self)
end

#child_nodesObject Also known as: deconstruct



5610
5611
5612
# File 'lib/syntax_tree/node.rb', line 5610

def child_nodes
  [statement, predicate]
end

#deconstruct_keys(_keys) ⇒ Object



5616
5617
5618
5619
5620
5621
5622
5623
# File 'lib/syntax_tree/node.rb', line 5616

def deconstruct_keys(_keys)
  {
    statement: statement,
    predicate: predicate,
    location: location,
    comments: comments
  }
end

#format(q) ⇒ Object



5625
5626
5627
# File 'lib/syntax_tree/node.rb', line 5625

def format(q)
  ConditionalModFormatter.new("if", self).format(q)
end