Class: SyntaxTree::Unless

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

Overview

Unless represents the first clause in an unless chain.

unless predicate
end

Instance Attribute Summary collapse

Attributes inherited from Node

#location

Instance Method Summary collapse

Methods inherited from Node

#pretty_print, #to_json

Constructor Details

#initialize(predicate:, statements:, consequent:, location:, comments: []) ⇒ Unless

Returns a new instance of Unless.



8343
8344
8345
8346
8347
8348
8349
8350
8351
8352
8353
8354
8355
# File 'lib/syntax_tree/node.rb', line 8343

def initialize(
  predicate:,
  statements:,
  consequent:,
  location:,
  comments: []
)
  @predicate = predicate
  @statements = statements
  @consequent = consequent
  @location = location
  @comments = comments
end

Instance Attribute Details

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



8341
8342
8343
# File 'lib/syntax_tree/node.rb', line 8341

def comments
  @comments
end

#consequentObject (readonly)

nil, Elsif, Else

the next clause in the chain



8338
8339
8340
# File 'lib/syntax_tree/node.rb', line 8338

def consequent
  @consequent
end

#predicateObject (readonly)

untyped

the expression to be checked



8332
8333
8334
# File 'lib/syntax_tree/node.rb', line 8332

def predicate
  @predicate
end

#statementsObject (readonly)

Statements

the expressions to be executed



8335
8336
8337
# File 'lib/syntax_tree/node.rb', line 8335

def statements
  @statements
end

Instance Method Details

#accept(visitor) ⇒ Object



8357
8358
8359
# File 'lib/syntax_tree/node.rb', line 8357

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

#child_nodesObject Also known as: deconstruct



8361
8362
8363
# File 'lib/syntax_tree/node.rb', line 8361

def child_nodes
  [predicate, statements, consequent]
end

#deconstruct_keys(keys) ⇒ Object



8367
8368
8369
8370
8371
8372
8373
8374
8375
# File 'lib/syntax_tree/node.rb', line 8367

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

#format(q) ⇒ Object



8377
8378
8379
# File 'lib/syntax_tree/node.rb', line 8377

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