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

#pretty_print, #to_json

Constructor Details

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

Returns a new instance of IfMod.



5415
5416
5417
5418
5419
5420
# File 'lib/syntax_tree/node.rb', line 5415

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



5413
5414
5415
# File 'lib/syntax_tree/node.rb', line 5413

def comments
  @comments
end

#predicateObject (readonly)

untyped

the expression to be checked



5410
5411
5412
# File 'lib/syntax_tree/node.rb', line 5410

def predicate
  @predicate
end

#statementObject (readonly)

untyped

the expression to be executed



5407
5408
5409
# File 'lib/syntax_tree/node.rb', line 5407

def statement
  @statement
end

Instance Method Details

#accept(visitor) ⇒ Object



5422
5423
5424
# File 'lib/syntax_tree/node.rb', line 5422

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

#child_nodesObject Also known as: deconstruct



5426
5427
5428
# File 'lib/syntax_tree/node.rb', line 5426

def child_nodes
  [statement, predicate]
end

#deconstruct_keys(keys) ⇒ Object



5432
5433
5434
5435
5436
5437
5438
5439
# File 'lib/syntax_tree/node.rb', line 5432

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

#format(q) ⇒ Object



5441
5442
5443
# File 'lib/syntax_tree/node.rb', line 5441

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