Class: SyntaxTree::If
Overview
If represents the first clause in an if
chain.
if 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
- untyped
-
the expression to be checked.
-
#statements ⇒ Object
readonly
- Statements
-
the expressions to be executed.
Attributes inherited from Node
Instance Method Summary collapse
- #accept(visitor) ⇒ Object
- #child_nodes ⇒ Object (also: #deconstruct)
- #deconstruct_keys(_keys) ⇒ Object
- #format(q) ⇒ Object
-
#initialize(predicate:, statements:, consequent:, location:, comments: []) ⇒ If
constructor
A new instance of If.
Methods inherited from Node
#construct_keys, #pretty_print, #to_json
Constructor Details
#initialize(predicate:, statements:, consequent:, location:, comments: []) ⇒ If
Returns a new instance of If.
5386 5387 5388 5389 5390 5391 5392 5393 5394 5395 5396 5397 5398 |
# File 'lib/syntax_tree/node.rb', line 5386 def initialize( predicate:, statements:, consequent:, location:, comments: [] ) @predicate = predicate @statements = statements @consequent = consequent @location = location @comments = comments end |
Instance Attribute Details
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
5384 5385 5386 |
# File 'lib/syntax_tree/node.rb', line 5384 def comments @comments end |
#consequent ⇒ Object (readonly)
- nil, Elsif, Else
-
the next clause in the chain
5381 5382 5383 |
# File 'lib/syntax_tree/node.rb', line 5381 def consequent @consequent end |
#predicate ⇒ Object (readonly)
- untyped
-
the expression to be checked
5375 5376 5377 |
# File 'lib/syntax_tree/node.rb', line 5375 def predicate @predicate end |
#statements ⇒ Object (readonly)
- Statements
-
the expressions to be executed
5378 5379 5380 |
# File 'lib/syntax_tree/node.rb', line 5378 def statements @statements end |
Instance Method Details
#accept(visitor) ⇒ Object
5400 5401 5402 |
# File 'lib/syntax_tree/node.rb', line 5400 def accept(visitor) visitor.visit_if(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
5404 5405 5406 |
# File 'lib/syntax_tree/node.rb', line 5404 def child_nodes [predicate, statements, consequent] end |
#deconstruct_keys(_keys) ⇒ Object
5410 5411 5412 5413 5414 5415 5416 5417 5418 |
# File 'lib/syntax_tree/node.rb', line 5410 def deconstruct_keys(_keys) { predicate: predicate, statements: statements, consequent: consequent, location: location, comments: comments } end |
#format(q) ⇒ Object
5420 5421 5422 |
# File 'lib/syntax_tree/node.rb', line 5420 def format(q) ConditionalFormatter.new("if", self).format(q) end |