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
Constructor Details
#initialize(predicate:, statements:, consequent:, location:, comments: []) ⇒ If
Returns a new instance of If.
5220 5221 5222 5223 5224 5225 5226 5227 5228 5229 5230 5231 5232 |
# File 'lib/syntax_tree/node.rb', line 5220 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
5218 5219 5220 |
# File 'lib/syntax_tree/node.rb', line 5218 def comments @comments end |
#consequent ⇒ Object (readonly)
- nil, Elsif, Else
-
the next clause in the chain
5215 5216 5217 |
# File 'lib/syntax_tree/node.rb', line 5215 def consequent @consequent end |
#predicate ⇒ Object (readonly)
- untyped
-
the expression to be checked
5209 5210 5211 |
# File 'lib/syntax_tree/node.rb', line 5209 def predicate @predicate end |
#statements ⇒ Object (readonly)
- Statements
-
the expressions to be executed
5212 5213 5214 |
# File 'lib/syntax_tree/node.rb', line 5212 def statements @statements end |
Instance Method Details
#accept(visitor) ⇒ Object
5234 5235 5236 |
# File 'lib/syntax_tree/node.rb', line 5234 def accept(visitor) visitor.visit_if(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
5238 5239 5240 |
# File 'lib/syntax_tree/node.rb', line 5238 def child_nodes [predicate, statements, consequent] end |
#deconstruct_keys(keys) ⇒ Object
5244 5245 5246 5247 5248 5249 5250 5251 5252 |
# File 'lib/syntax_tree/node.rb', line 5244 def deconstruct_keys(keys) { predicate: predicate, statements: statements, consequent: consequent, location: location, comments: comments } end |
#format(q) ⇒ Object
5254 5255 5256 |
# File 'lib/syntax_tree/node.rb', line 5254 def format(q) ConditionalFormatter.new("if", self).format(q) end |