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.



5499
5500
5501
5502
5503
5504
# File 'lib/syntax_tree/node.rb', line 5499

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



5497
5498
5499
# File 'lib/syntax_tree/node.rb', line 5497

def comments
  @comments
end

#predicateObject (readonly)

untyped

the expression to be checked



5494
5495
5496
# File 'lib/syntax_tree/node.rb', line 5494

def predicate
  @predicate
end

#statementObject (readonly)

untyped

the expression to be executed



5491
5492
5493
# File 'lib/syntax_tree/node.rb', line 5491

def statement
  @statement
end

Instance Method Details

#accept(visitor) ⇒ Object



5506
5507
5508
# File 'lib/syntax_tree/node.rb', line 5506

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

#child_nodesObject Also known as: deconstruct



5510
5511
5512
# File 'lib/syntax_tree/node.rb', line 5510

def child_nodes
  [statement, predicate]
end

#deconstruct_keys(_keys) ⇒ Object



5516
5517
5518
5519
5520
5521
5522
5523
# File 'lib/syntax_tree/node.rb', line 5516

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

#format(q) ⇒ Object



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

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