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.
5622 5623 5624 5625 5626 5627 5628 |
# File 'lib/syntax_tree/node.rb', line 5622 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
5620 5621 5622 |
# File 'lib/syntax_tree/node.rb', line 5620 def comments @comments end |
#falsy ⇒ Object (readonly)
- untyped
-
the expression to be executed if the predicate is falsy
5617 5618 5619 |
# File 'lib/syntax_tree/node.rb', line 5617 def falsy @falsy end |
#predicate ⇒ Object (readonly)
- untyped
-
the expression to be checked
5611 5612 5613 |
# File 'lib/syntax_tree/node.rb', line 5611 def predicate @predicate end |
#truthy ⇒ Object (readonly)
- untyped
-
the expression to be executed if the predicate is truthy
5614 5615 5616 |
# File 'lib/syntax_tree/node.rb', line 5614 def truthy @truthy end |
Instance Method Details
#accept(visitor) ⇒ Object
5630 5631 5632 |
# File 'lib/syntax_tree/node.rb', line 5630 def accept(visitor) visitor.visit_if_op(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
5634 5635 5636 |
# File 'lib/syntax_tree/node.rb', line 5634 def child_nodes [predicate, truthy, falsy] end |
#deconstruct_keys(_keys) ⇒ Object
5640 5641 5642 5643 5644 5645 5646 5647 5648 |
# File 'lib/syntax_tree/node.rb', line 5640 def deconstruct_keys(_keys) { predicate: predicate, truthy: truthy, falsy: falsy, location: location, comments: comments } end |
#format(q) ⇒ Object
5650 5651 5652 5653 5654 5655 5656 5657 5658 5659 5660 5661 5662 5663 5664 5665 |
# File 'lib/syntax_tree/node.rb', line 5650 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 |