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.
4753 4754 4755 4756 4757 4758 4759 |
# File 'lib/syntax_tree/node.rb', line 4753 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
4751 4752 4753 |
# File 'lib/syntax_tree/node.rb', line 4751 def comments @comments end |
#falsy ⇒ Object (readonly)
- untyped
-
the expression to be executed if the predicate is falsy
4748 4749 4750 |
# File 'lib/syntax_tree/node.rb', line 4748 def falsy @falsy end |
#predicate ⇒ Object (readonly)
- untyped
-
the expression to be checked
4742 4743 4744 |
# File 'lib/syntax_tree/node.rb', line 4742 def predicate @predicate end |
#truthy ⇒ Object (readonly)
- untyped
-
the expression to be executed if the predicate is truthy
4745 4746 4747 |
# File 'lib/syntax_tree/node.rb', line 4745 def truthy @truthy end |
Instance Method Details
#accept(visitor) ⇒ Object
4761 4762 4763 |
# File 'lib/syntax_tree/node.rb', line 4761 def accept(visitor) visitor.visit_if_op(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
4765 4766 4767 |
# File 'lib/syntax_tree/node.rb', line 4765 def child_nodes [predicate, truthy, falsy] end |
#deconstruct_keys(keys) ⇒ Object
4771 4772 4773 4774 4775 4776 4777 4778 4779 |
# File 'lib/syntax_tree/node.rb', line 4771 def deconstruct_keys(keys) { predicate: predicate, truthy: truthy, falsy: falsy, location: location, comments: comments } end |
#format(q) ⇒ Object
4781 4782 4783 4784 4785 4786 4787 4788 4789 4790 4791 4792 4793 4794 4795 |
# File 'lib/syntax_tree/node.rb', line 4781 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 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 |