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

#construct_keys, #pretty_print, #to_json

Constructor Details

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

Returns a new instance of Unless.



9014
9015
9016
9017
9018
9019
9020
9021
9022
9023
9024
9025
9026
# File 'lib/syntax_tree/node.rb', line 9014

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



9012
9013
9014
# File 'lib/syntax_tree/node.rb', line 9012

def comments
  @comments
end

#consequentObject (readonly)

nil, Elsif, Else

the next clause in the chain



9009
9010
9011
# File 'lib/syntax_tree/node.rb', line 9009

def consequent
  @consequent
end

#predicateObject (readonly)

untyped

the expression to be checked



9003
9004
9005
# File 'lib/syntax_tree/node.rb', line 9003

def predicate
  @predicate
end

#statementsObject (readonly)

Statements

the expressions to be executed



9006
9007
9008
# File 'lib/syntax_tree/node.rb', line 9006

def statements
  @statements
end

Instance Method Details

#accept(visitor) ⇒ Object



9028
9029
9030
# File 'lib/syntax_tree/node.rb', line 9028

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

#child_nodesObject Also known as: deconstruct



9032
9033
9034
# File 'lib/syntax_tree/node.rb', line 9032

def child_nodes
  [predicate, statements, consequent]
end

#deconstruct_keys(_keys) ⇒ Object



9038
9039
9040
9041
9042
9043
9044
9045
9046
# File 'lib/syntax_tree/node.rb', line 9038

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

#format(q) ⇒ Object



9048
9049
9050
# File 'lib/syntax_tree/node.rb', line 9048

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