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.



9189
9190
9191
9192
9193
9194
# File 'lib/syntax_tree/node.rb', line 9189

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



9187
9188
9189
# File 'lib/syntax_tree/node.rb', line 9187

def comments
  @comments
end

#predicateObject (readonly)

untyped

the expression to be checked



9184
9185
9186
# File 'lib/syntax_tree/node.rb', line 9184

def predicate
  @predicate
end

#statementObject (readonly)

untyped

the expression to be executed



9181
9182
9183
# File 'lib/syntax_tree/node.rb', line 9181

def statement
  @statement
end

Instance Method Details

#accept(visitor) ⇒ Object



9196
9197
9198
# File 'lib/syntax_tree/node.rb', line 9196

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

#child_nodesObject Also known as: deconstruct



9200
9201
9202
# File 'lib/syntax_tree/node.rb', line 9200

def child_nodes
  [statement, predicate]
end

#deconstruct_keys(_keys) ⇒ Object



9206
9207
9208
9209
9210
9211
9212
9213
# File 'lib/syntax_tree/node.rb', line 9206

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

#format(q) ⇒ Object



9215
9216
9217
# File 'lib/syntax_tree/node.rb', line 9215

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