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.
5566 5567 5568 5569 5570 5571 5572 5573 5574 5575 5576 5577 5578 |
# File 'lib/syntax_tree/node.rb', line 5566 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
5564 5565 5566 |
# File 'lib/syntax_tree/node.rb', line 5564 def comments @comments end |
#consequent ⇒ Object (readonly)
- nil, Elsif, Else
-
the next clause in the chain
5561 5562 5563 |
# File 'lib/syntax_tree/node.rb', line 5561 def consequent @consequent end |
#predicate ⇒ Object (readonly)
- untyped
-
the expression to be checked
5555 5556 5557 |
# File 'lib/syntax_tree/node.rb', line 5555 def predicate @predicate end |
#statements ⇒ Object (readonly)
- Statements
-
the expressions to be executed
5558 5559 5560 |
# File 'lib/syntax_tree/node.rb', line 5558 def statements @statements end |
Instance Method Details
#accept(visitor) ⇒ Object
5580 5581 5582 |
# File 'lib/syntax_tree/node.rb', line 5580 def accept(visitor) visitor.visit_if(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
5584 5585 5586 |
# File 'lib/syntax_tree/node.rb', line 5584 def child_nodes [predicate, statements, consequent] end |
#deconstruct_keys(_keys) ⇒ Object
5590 5591 5592 5593 5594 5595 5596 5597 5598 |
# File 'lib/syntax_tree/node.rb', line 5590 def deconstruct_keys(_keys) { predicate: predicate, statements: statements, consequent: consequent, location: location, comments: comments } end |
#format(q) ⇒ Object
5600 5601 5602 |
# File 'lib/syntax_tree/node.rb', line 5600 def format(q) ConditionalFormatter.new("if", self).format(q) end |