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



5764
5765
5766
5767
5768
5769
# File 'lib/syntax_tree/node.rb', line 5764

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



5762
5763
5764
# File 'lib/syntax_tree/node.rb', line 5762

def comments
  @comments
end

#predicateObject (readonly)

untyped

the expression to be checked



5759
5760
5761
# File 'lib/syntax_tree/node.rb', line 5759

def predicate
  @predicate
end

#statementObject (readonly)

untyped

the expression to be executed



5756
5757
5758
# File 'lib/syntax_tree/node.rb', line 5756

def statement
  @statement
end

Instance Method Details

#accept(visitor) ⇒ Object



5771
5772
5773
# File 'lib/syntax_tree/node.rb', line 5771

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

#child_nodesObject Also known as: deconstruct



5775
5776
5777
# File 'lib/syntax_tree/node.rb', line 5775

def child_nodes
  [statement, predicate]
end

#deconstruct_keys(_keys) ⇒ Object



5781
5782
5783
5784
5785
5786
5787
5788
# File 'lib/syntax_tree/node.rb', line 5781

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

#format(q) ⇒ Object



5790
5791
5792
# File 'lib/syntax_tree/node.rb', line 5790

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