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.



9136
9137
9138
9139
9140
9141
9142
9143
9144
9145
9146
9147
9148
# File 'lib/syntax_tree/node.rb', line 9136

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



9134
9135
9136
# File 'lib/syntax_tree/node.rb', line 9134

def comments
  @comments
end

#consequentObject (readonly)

nil, Elsif, Else

the next clause in the chain



9131
9132
9133
# File 'lib/syntax_tree/node.rb', line 9131

def consequent
  @consequent
end

#predicateObject (readonly)

untyped

the expression to be checked



9125
9126
9127
# File 'lib/syntax_tree/node.rb', line 9125

def predicate
  @predicate
end

#statementsObject (readonly)

Statements

the expressions to be executed



9128
9129
9130
# File 'lib/syntax_tree/node.rb', line 9128

def statements
  @statements
end

Instance Method Details

#accept(visitor) ⇒ Object



9150
9151
9152
# File 'lib/syntax_tree/node.rb', line 9150

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

#child_nodesObject Also known as: deconstruct



9154
9155
9156
# File 'lib/syntax_tree/node.rb', line 9154

def child_nodes
  [predicate, statements, consequent]
end

#deconstruct_keys(_keys) ⇒ Object



9160
9161
9162
9163
9164
9165
9166
9167
9168
# File 'lib/syntax_tree/node.rb', line 9160

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

#format(q) ⇒ Object



9170
9171
9172
# File 'lib/syntax_tree/node.rb', line 9170

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