Class: SyntaxTree::UnlessMod

Inherits:
Node
  • Object
show all
Defined in:
lib/syntax_tree/node.rb

Overview

UnlessMod represents the modifier form of an unless statement.

expression unless 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: []) ⇒ UnlessMod

Returns a new instance of UnlessMod.



9144
9145
9146
9147
9148
9149
# File 'lib/syntax_tree/node.rb', line 9144

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



9142
9143
9144
# File 'lib/syntax_tree/node.rb', line 9142

def comments
  @comments
end

#predicateObject (readonly)

untyped

the expression to be checked



9139
9140
9141
# File 'lib/syntax_tree/node.rb', line 9139

def predicate
  @predicate
end

#statementObject (readonly)

untyped

the expression to be executed



9136
9137
9138
# File 'lib/syntax_tree/node.rb', line 9136

def statement
  @statement
end

Instance Method Details

#accept(visitor) ⇒ Object



9151
9152
9153
# File 'lib/syntax_tree/node.rb', line 9151

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

#child_nodesObject Also known as: deconstruct



9155
9156
9157
# File 'lib/syntax_tree/node.rb', line 9155

def child_nodes
  [statement, predicate]
end

#deconstruct_keys(_keys) ⇒ Object



9161
9162
9163
9164
9165
9166
9167
9168
# File 'lib/syntax_tree/node.rb', line 9161

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

#format(q) ⇒ Object



9170
9171
9172
# File 'lib/syntax_tree/node.rb', line 9170

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