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.



9091
9092
9093
9094
9095
9096
9097
9098
9099
9100
9101
9102
9103
# File 'lib/syntax_tree/node.rb', line 9091

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



9089
9090
9091
# File 'lib/syntax_tree/node.rb', line 9089

def comments
  @comments
end

#consequentObject (readonly)

nil, Elsif, Else

the next clause in the chain



9086
9087
9088
# File 'lib/syntax_tree/node.rb', line 9086

def consequent
  @consequent
end

#predicateObject (readonly)

untyped

the expression to be checked



9080
9081
9082
# File 'lib/syntax_tree/node.rb', line 9080

def predicate
  @predicate
end

#statementsObject (readonly)

Statements

the expressions to be executed



9083
9084
9085
# File 'lib/syntax_tree/node.rb', line 9083

def statements
  @statements
end

Instance Method Details

#accept(visitor) ⇒ Object



9105
9106
9107
# File 'lib/syntax_tree/node.rb', line 9105

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

#child_nodesObject Also known as: deconstruct



9109
9110
9111
# File 'lib/syntax_tree/node.rb', line 9109

def child_nodes
  [predicate, statements, consequent]
end

#deconstruct_keys(_keys) ⇒ Object



9115
9116
9117
9118
9119
9120
9121
9122
9123
# File 'lib/syntax_tree/node.rb', line 9115

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

#format(q) ⇒ Object



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

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