Class: SyntaxTree::IfOp
Overview
IfOp represents a ternary clause.
predicate ? truthy : falsy
Instance Attribute Summary collapse
-
#comments ⇒ Object
readonly
[Array[ Comment | EmbDoc ]] the comments attached to this node.
-
#falsy ⇒ Object
readonly
[untyped] the expression to be executed if the predicate is falsy.
-
#predicate ⇒ Object
readonly
[untyped] the expression to be checked.
-
#truthy ⇒ Object
readonly
[untyped] the expression to be executed if the predicate is truthy.
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:, truthy:, falsy:, location:, comments: []) ⇒ IfOp
constructor
A new instance of IfOp.
Methods inherited from Node
Constructor Details
#initialize(predicate:, truthy:, falsy:, location:, comments: []) ⇒ IfOp
Returns a new instance of IfOp.
5277 5278 5279 5280 5281 5282 5283 |
# File 'lib/syntax_tree/node.rb', line 5277 def initialize(predicate:, truthy:, falsy:, location:, comments: []) @predicate = predicate @truthy = truthy @falsy = falsy @location = location @comments = comments end |
Instance Attribute Details
#comments ⇒ Object (readonly)
[Array[ Comment | EmbDoc ]] the comments attached to this node
5275 5276 5277 |
# File 'lib/syntax_tree/node.rb', line 5275 def comments @comments end |
#falsy ⇒ Object (readonly)
[untyped] the expression to be executed if the predicate is falsy
5272 5273 5274 |
# File 'lib/syntax_tree/node.rb', line 5272 def falsy @falsy end |
#predicate ⇒ Object (readonly)
[untyped] the expression to be checked
5266 5267 5268 |
# File 'lib/syntax_tree/node.rb', line 5266 def predicate @predicate end |
#truthy ⇒ Object (readonly)
[untyped] the expression to be executed if the predicate is truthy
5269 5270 5271 |
# File 'lib/syntax_tree/node.rb', line 5269 def truthy @truthy end |
Instance Method Details
#accept(visitor) ⇒ Object
5285 5286 5287 |
# File 'lib/syntax_tree/node.rb', line 5285 def accept(visitor) visitor.visit_if_op(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
5289 5290 5291 |
# File 'lib/syntax_tree/node.rb', line 5289 def child_nodes [predicate, truthy, falsy] end |
#deconstruct_keys(keys) ⇒ Object
5295 5296 5297 5298 5299 5300 5301 5302 5303 |
# File 'lib/syntax_tree/node.rb', line 5295 def deconstruct_keys(keys) { predicate: predicate, truthy: truthy, falsy: falsy, location: location, comments: comments } end |
#format(q) ⇒ Object
5305 5306 5307 5308 5309 5310 5311 5312 5313 5314 5315 5316 5317 5318 5319 |
# File 'lib/syntax_tree/node.rb', line 5305 def format(q) force_flat = [ Alias, Assign, Break, Command, CommandCall, Heredoc, If, IfMod, IfOp, Lambda, MAssign, Next, OpAssign, RescueMod, Return, Return0, Super, Undef, Unless, UnlessMod, UntilMod, VarAlias, VoidStmt, WhileMod, Yield, Yield0, ZSuper ] if q.parent.is_a?(Paren) || force_flat.include?(truthy.class) || force_flat.include?(falsy.class) q.group { format_flat(q) } return end q.group { q.if_break { format_break(q) }.if_flat { format_flat(q) } } end |