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

#pretty_print, #to_json

Constructor Details

#initialize(statement:, predicate:, location:, comments: []) ⇒ UnlessMod

Returns a new instance of UnlessMod.



8396
8397
8398
8399
8400
8401
# File 'lib/syntax_tree/node.rb', line 8396

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



8394
8395
8396
# File 'lib/syntax_tree/node.rb', line 8394

def comments
  @comments
end

#predicateObject (readonly)

untyped

the expression to be checked



8391
8392
8393
# File 'lib/syntax_tree/node.rb', line 8391

def predicate
  @predicate
end

#statementObject (readonly)

untyped

the expression to be executed



8388
8389
8390
# File 'lib/syntax_tree/node.rb', line 8388

def statement
  @statement
end

Instance Method Details

#accept(visitor) ⇒ Object



8403
8404
8405
# File 'lib/syntax_tree/node.rb', line 8403

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

#child_nodesObject Also known as: deconstruct



8407
8408
8409
# File 'lib/syntax_tree/node.rb', line 8407

def child_nodes
  [statement, predicate]
end

#deconstruct_keys(keys) ⇒ Object



8413
8414
8415
8416
8417
8418
8419
8420
# File 'lib/syntax_tree/node.rb', line 8413

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

#format(q) ⇒ Object



8422
8423
8424
# File 'lib/syntax_tree/node.rb', line 8422

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