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.



4892
4893
4894
4895
4896
4897
# File 'lib/syntax_tree/node.rb', line 4892

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



4890
4891
4892
# File 'lib/syntax_tree/node.rb', line 4890

def comments
  @comments
end

#predicateObject (readonly)

untyped

the expression to be checked



4887
4888
4889
# File 'lib/syntax_tree/node.rb', line 4887

def predicate
  @predicate
end

#statementObject (readonly)

untyped

the expression to be executed



4884
4885
4886
# File 'lib/syntax_tree/node.rb', line 4884

def statement
  @statement
end

Instance Method Details

#accept(visitor) ⇒ Object



4899
4900
4901
# File 'lib/syntax_tree/node.rb', line 4899

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

#child_nodesObject Also known as: deconstruct



4903
4904
4905
# File 'lib/syntax_tree/node.rb', line 4903

def child_nodes
  [statement, predicate]
end

#deconstruct_keys(keys) ⇒ Object



4909
4910
4911
4912
4913
4914
4915
4916
# File 'lib/syntax_tree/node.rb', line 4909

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

#format(q) ⇒ Object



4918
4919
4920
# File 'lib/syntax_tree/node.rb', line 4918

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