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.



5575
5576
5577
5578
5579
5580
# File 'lib/syntax_tree/node.rb', line 5575

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



5573
5574
5575
# File 'lib/syntax_tree/node.rb', line 5573

def comments
  @comments
end

#predicateObject (readonly)

untyped

the expression to be checked



5570
5571
5572
# File 'lib/syntax_tree/node.rb', line 5570

def predicate
  @predicate
end

#statementObject (readonly)

untyped

the expression to be executed



5567
5568
5569
# File 'lib/syntax_tree/node.rb', line 5567

def statement
  @statement
end

Instance Method Details

#accept(visitor) ⇒ Object



5582
5583
5584
# File 'lib/syntax_tree/node.rb', line 5582

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

#child_nodesObject Also known as: deconstruct



5586
5587
5588
# File 'lib/syntax_tree/node.rb', line 5586

def child_nodes
  [statement, predicate]
end

#deconstruct_keys(_keys) ⇒ Object



5592
5593
5594
5595
5596
5597
5598
5599
# File 'lib/syntax_tree/node.rb', line 5592

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

#format(q) ⇒ Object



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

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