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.
5303 5304 5305 5306 5307 5308 5309 5310 5311 5312 5313 5314 5315 |
# File 'lib/syntax_tree/node.rb', line 5303 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
5301 5302 5303 |
# File 'lib/syntax_tree/node.rb', line 5301 def comments @comments end |
#consequent ⇒ Object (readonly)
- nil, Elsif, Else
-
the next clause in the chain
5298 5299 5300 |
# File 'lib/syntax_tree/node.rb', line 5298 def consequent @consequent end |
#predicate ⇒ Object (readonly)
- untyped
-
the expression to be checked
5292 5293 5294 |
# File 'lib/syntax_tree/node.rb', line 5292 def predicate @predicate end |
#statements ⇒ Object (readonly)
- Statements
-
the expressions to be executed
5295 5296 5297 |
# File 'lib/syntax_tree/node.rb', line 5295 def statements @statements end |
Instance Method Details
#accept(visitor) ⇒ Object
5317 5318 5319 |
# File 'lib/syntax_tree/node.rb', line 5317 def accept(visitor) visitor.visit_if(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
5321 5322 5323 |
# File 'lib/syntax_tree/node.rb', line 5321 def child_nodes [predicate, statements, consequent] end |
#deconstruct_keys(_keys) ⇒ Object
5327 5328 5329 5330 5331 5332 5333 5334 5335 |
# File 'lib/syntax_tree/node.rb', line 5327 def deconstruct_keys(_keys) { predicate: predicate, statements: statements, consequent: consequent, location: location, comments: comments } end |
#format(q) ⇒ Object
5337 5338 5339 |
# File 'lib/syntax_tree/node.rb', line 5337 def format(q) ConditionalFormatter.new("if", self).format(q) end |