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.



9178
9179
9180
9181
9182
9183
9184
9185
9186
9187
9188
9189
9190
# File 'lib/syntax_tree/node.rb', line 9178

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



9176
9177
9178
# File 'lib/syntax_tree/node.rb', line 9176

def comments
  @comments
end

#consequentObject (readonly)

nil, Elsif, Else

the next clause in the chain



9173
9174
9175
# File 'lib/syntax_tree/node.rb', line 9173

def consequent
  @consequent
end

#predicateObject (readonly)

untyped

the expression to be checked



9167
9168
9169
# File 'lib/syntax_tree/node.rb', line 9167

def predicate
  @predicate
end

#statementsObject (readonly)

Statements

the expressions to be executed



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

def statements
  @statements
end

Instance Method Details

#accept(visitor) ⇒ Object



9192
9193
9194
# File 'lib/syntax_tree/node.rb', line 9192

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

#child_nodesObject Also known as: deconstruct



9196
9197
9198
# File 'lib/syntax_tree/node.rb', line 9196

def child_nodes
  [predicate, statements, consequent]
end

#deconstruct_keys(_keys) ⇒ Object



9202
9203
9204
9205
9206
9207
9208
9209
9210
# File 'lib/syntax_tree/node.rb', line 9202

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

#format(q) ⇒ Object



9212
9213
9214
# File 'lib/syntax_tree/node.rb', line 9212

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