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.



5545
5546
5547
5548
5549
5550
# File 'lib/syntax_tree/node.rb', line 5545

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



5543
5544
5545
# File 'lib/syntax_tree/node.rb', line 5543

def comments
  @comments
end

#predicateObject (readonly)

untyped

the expression to be checked



5540
5541
5542
# File 'lib/syntax_tree/node.rb', line 5540

def predicate
  @predicate
end

#statementObject (readonly)

untyped

the expression to be executed



5537
5538
5539
# File 'lib/syntax_tree/node.rb', line 5537

def statement
  @statement
end

Instance Method Details

#accept(visitor) ⇒ Object



5552
5553
5554
# File 'lib/syntax_tree/node.rb', line 5552

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

#child_nodesObject Also known as: deconstruct



5556
5557
5558
# File 'lib/syntax_tree/node.rb', line 5556

def child_nodes
  [statement, predicate]
end

#deconstruct_keys(_keys) ⇒ Object



5562
5563
5564
5565
5566
5567
5568
5569
# File 'lib/syntax_tree/node.rb', line 5562

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

#format(q) ⇒ Object



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

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