Class: SyntaxTree::Else
Overview
Else represents the end of an if, unless, or case chain.
if variable
else
end
Instance Attribute Summary collapse
-
#comments ⇒ Object
readonly
- Array[ Comment | EmbDoc ]
-
the comments attached to this node.
-
#keyword ⇒ Object
readonly
- Kw
-
the else keyword.
-
#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(keyword:, statements:, location:, comments: []) ⇒ Else
constructor
A new instance of Else.
Methods inherited from Node
Constructor Details
#initialize(keyword:, statements:, location:, comments: []) ⇒ Else
Returns a new instance of Else.
3591 3592 3593 3594 3595 3596 |
# File 'lib/syntax_tree/node.rb', line 3591 def initialize(keyword:, statements:, location:, comments: []) @keyword = keyword @statements = statements @location = location @comments = comments end |
Instance Attribute Details
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
3589 3590 3591 |
# File 'lib/syntax_tree/node.rb', line 3589 def comments @comments end |
#keyword ⇒ Object (readonly)
- Kw
-
the else keyword
3583 3584 3585 |
# File 'lib/syntax_tree/node.rb', line 3583 def keyword @keyword end |
#statements ⇒ Object (readonly)
- Statements
-
the expressions to be executed
3586 3587 3588 |
# File 'lib/syntax_tree/node.rb', line 3586 def statements @statements end |
Instance Method Details
#accept(visitor) ⇒ Object
3598 3599 3600 |
# File 'lib/syntax_tree/node.rb', line 3598 def accept(visitor) visitor.visit_else(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
3602 3603 3604 |
# File 'lib/syntax_tree/node.rb', line 3602 def child_nodes [keyword, statements] end |
#deconstruct_keys(keys) ⇒ Object
3608 3609 3610 3611 3612 3613 3614 3615 |
# File 'lib/syntax_tree/node.rb', line 3608 def deconstruct_keys(keys) { keyword: keyword, statements: statements, location: location, comments: comments } end |
#format(q) ⇒ Object
3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 |
# File 'lib/syntax_tree/node.rb', line 3617 def format(q) q.group do q.format(keyword) unless statements.empty? q.indent do q.breakable(force: true) q.format(statements) end end end end |