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.



9462
9463
9464
9465
9466
9467
# File 'lib/syntax_tree/node.rb', line 9462

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



9460
9461
9462
# File 'lib/syntax_tree/node.rb', line 9460

def comments
  @comments
end

#predicateObject (readonly)

untyped

the expression to be checked



9457
9458
9459
# File 'lib/syntax_tree/node.rb', line 9457

def predicate
  @predicate
end

#statementObject (readonly)

untyped

the expression to be executed



9454
9455
9456
# File 'lib/syntax_tree/node.rb', line 9454

def statement
  @statement
end

Instance Method Details

#accept(visitor) ⇒ Object



9469
9470
9471
# File 'lib/syntax_tree/node.rb', line 9469

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

#child_nodesObject Also known as: deconstruct



9473
9474
9475
# File 'lib/syntax_tree/node.rb', line 9473

def child_nodes
  [statement, predicate]
end

#deconstruct_keys(_keys) ⇒ Object



9479
9480
9481
9482
9483
9484
9485
9486
# File 'lib/syntax_tree/node.rb', line 9479

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

#format(q) ⇒ Object



9488
9489
9490
# File 'lib/syntax_tree/node.rb', line 9488

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