Class: SyntaxTree::UnlessNode
Overview
Unless represents the first clause in an unless
chain.
unless predicate
end
Instance Attribute Summary collapse
-
#comments ⇒ Object
readonly
- Array[ Comment | EmbDoc ]
-
the comments attached to this node.
-
#consequent ⇒ Object
readonly
- nil | Elsif | Else
-
the next clause in the chain.
-
#predicate ⇒ Object
readonly
- Node
-
the expression to be checked.
-
#statements ⇒ Object
readonly
- Statements
-
the expressions to be executed.
Attributes inherited from Node
Instance Method Summary collapse
- #===(other) ⇒ Object
- #accept(visitor) ⇒ Object
- #child_nodes ⇒ Object (also: #deconstruct)
- #copy(predicate: nil, statements: nil, consequent: nil, location: nil) ⇒ Object
- #deconstruct_keys(_keys) ⇒ Object
- #format(q) ⇒ Object
-
#initialize(predicate:, statements:, consequent:, location:) ⇒ UnlessNode
constructor
A new instance of UnlessNode.
-
#modifier? ⇒ Boolean
Checks if the node was originally found in the modifier form.
Methods inherited from Node
#construct_keys, #end_char, #pretty_print, #start_char, #to_json, #to_mermaid
Constructor Details
#initialize(predicate:, statements:, consequent:, location:) ⇒ UnlessNode
Returns a new instance of UnlessNode.
11321 11322 11323 11324 11325 11326 11327 |
# File 'lib/syntax_tree/node.rb', line 11321 def initialize(predicate:, statements:, consequent:, location:) @predicate = predicate @statements = statements @consequent = consequent @location = location @comments = [] end |
Instance Attribute Details
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
11319 11320 11321 |
# File 'lib/syntax_tree/node.rb', line 11319 def comments @comments end |
#consequent ⇒ Object (readonly)
- nil | Elsif | Else
-
the next clause in the chain
11316 11317 11318 |
# File 'lib/syntax_tree/node.rb', line 11316 def consequent @consequent end |
#predicate ⇒ Object (readonly)
- Node
-
the expression to be checked
11310 11311 11312 |
# File 'lib/syntax_tree/node.rb', line 11310 def predicate @predicate end |
#statements ⇒ Object (readonly)
- Statements
-
the expressions to be executed
11313 11314 11315 |
# File 'lib/syntax_tree/node.rb', line 11313 def statements @statements end |
Instance Method Details
#===(other) ⇒ Object
11366 11367 11368 11369 |
# File 'lib/syntax_tree/node.rb', line 11366 def ===(other) other.is_a?(UnlessNode) && predicate === other.predicate && statements === other.statements && consequent === other.consequent end |
#accept(visitor) ⇒ Object
11329 11330 11331 |
# File 'lib/syntax_tree/node.rb', line 11329 def accept(visitor) visitor.visit_unless(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
11333 11334 11335 |
# File 'lib/syntax_tree/node.rb', line 11333 def child_nodes [predicate, statements, consequent] end |
#copy(predicate: nil, statements: nil, consequent: nil, location: nil) ⇒ Object
11337 11338 11339 11340 11341 11342 11343 11344 11345 11346 11347 11348 |
# File 'lib/syntax_tree/node.rb', line 11337 def copy(predicate: nil, statements: nil, consequent: nil, location: nil) node = UnlessNode.new( predicate: predicate || self.predicate, statements: statements || self.statements, consequent: consequent || self.consequent, location: location || self.location ) node.comments.concat(comments.map(&:copy)) node end |
#deconstruct_keys(_keys) ⇒ Object
11352 11353 11354 11355 11356 11357 11358 11359 11360 |
# File 'lib/syntax_tree/node.rb', line 11352 def deconstruct_keys(_keys) { predicate: predicate, statements: statements, consequent: consequent, location: location, comments: comments } end |
#format(q) ⇒ Object
11362 11363 11364 |
# File 'lib/syntax_tree/node.rb', line 11362 def format(q) ConditionalFormatter.new("unless", self).format(q) end |
#modifier? ⇒ Boolean
Checks if the node was originally found in the modifier form.
11372 11373 11374 |
# File 'lib/syntax_tree/node.rb', line 11372 def modifier? predicate.location.start_char > statements.location.start_char end |