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
#construct_keys, #pretty_print, #to_json
Constructor Details
#initialize(predicate:, truthy:, falsy:, location:, comments: []) ⇒ IfOp
Returns a new instance of IfOp.
5442 5443 5444 5445 5446 5447 5448 |
# File 'lib/syntax_tree/node.rb', line 5442 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
5440 5441 5442 |
# File 'lib/syntax_tree/node.rb', line 5440 def comments @comments end |
#falsy ⇒ Object (readonly)
- untyped
-
the expression to be executed if the predicate is falsy
5437 5438 5439 |
# File 'lib/syntax_tree/node.rb', line 5437 def falsy @falsy end |
#predicate ⇒ Object (readonly)
- untyped
-
the expression to be checked
5431 5432 5433 |
# File 'lib/syntax_tree/node.rb', line 5431 def predicate @predicate end |
#truthy ⇒ Object (readonly)
- untyped
-
the expression to be executed if the predicate is truthy
5434 5435 5436 |
# File 'lib/syntax_tree/node.rb', line 5434 def truthy @truthy end |
Instance Method Details
#accept(visitor) ⇒ Object
5450 5451 5452 |
# File 'lib/syntax_tree/node.rb', line 5450 def accept(visitor) visitor.visit_if_op(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
5454 5455 5456 |
# File 'lib/syntax_tree/node.rb', line 5454 def child_nodes [predicate, truthy, falsy] end |
#deconstruct_keys(_keys) ⇒ Object
5460 5461 5462 5463 5464 5465 5466 5467 5468 |
# File 'lib/syntax_tree/node.rb', line 5460 def deconstruct_keys(_keys) { predicate: predicate, truthy: truthy, falsy: falsy, location: location, comments: comments } end |
#format(q) ⇒ Object
5470 5471 5472 5473 5474 5475 5476 5477 5478 5479 5480 5481 5482 5483 5484 5485 |
# File 'lib/syntax_tree/node.rb', line 5470 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 |