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.



9245
9246
9247
9248
9249
9250
# File 'lib/syntax_tree/node.rb', line 9245

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



9243
9244
9245
# File 'lib/syntax_tree/node.rb', line 9243

def comments
  @comments
end

#predicateObject (readonly)

untyped

the expression to be checked



9240
9241
9242
# File 'lib/syntax_tree/node.rb', line 9240

def predicate
  @predicate
end

#statementObject (readonly)

untyped

the expression to be executed



9237
9238
9239
# File 'lib/syntax_tree/node.rb', line 9237

def statement
  @statement
end

Instance Method Details

#accept(visitor) ⇒ Object



9252
9253
9254
# File 'lib/syntax_tree/node.rb', line 9252

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

#child_nodesObject Also known as: deconstruct



9256
9257
9258
# File 'lib/syntax_tree/node.rb', line 9256

def child_nodes
  [statement, predicate]
end

#deconstruct_keys(_keys) ⇒ Object



9262
9263
9264
9265
9266
9267
9268
9269
# File 'lib/syntax_tree/node.rb', line 9262

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

#format(q) ⇒ Object



9271
9272
9273
# File 'lib/syntax_tree/node.rb', line 9271

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