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.



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

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

Instance Attribute Details

#comments ⇒ Object (readonly)

[Array[ Comment | EmbDoc ]] the comments attached to this node



5532
5533
5534
# File 'lib/syntax_tree/node.rb', line 5532

def comments
  @comments
end

#predicate ⇒ Object (readonly)

[untyped] the expression to be checked



5529
5530
5531
# File 'lib/syntax_tree/node.rb', line 5529

def predicate
  @predicate
end

#statement ⇒ Object (readonly)

[untyped] the expression to be executed



5526
5527
5528
# File 'lib/syntax_tree/node.rb', line 5526

def statement
  @statement
end

Instance Method Details

#accept(visitor) ⇒ Object



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

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

#child_nodes ⇒ Object Also known as: deconstruct



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

def child_nodes
  [statement, predicate]
end

#deconstruct_keys(_keys) ⇒ Object



5551
5552
5553
5554
5555
5556
5557
5558
# File 'lib/syntax_tree/node.rb', line 5551

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

#format(q) ⇒ Object



5560
5561
5562
# File 'lib/syntax_tree/node.rb', line 5560

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