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
#construct_keys, #pretty_print, #to_json
Constructor Details
#initialize(keyword:, statements:, location:, comments: []) ⇒ Else
Returns a new instance of Else.
4017 4018 4019 4020 4021 4022 |
# File 'lib/syntax_tree/node.rb', line 4017 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
4015 4016 4017 |
# File 'lib/syntax_tree/node.rb', line 4015 def comments @comments end |
#keyword ⇒ Object (readonly)
[Kw] the else keyword
4009 4010 4011 |
# File 'lib/syntax_tree/node.rb', line 4009 def keyword @keyword end |
#statements ⇒ Object (readonly)
[Statements] the expressions to be executed
4012 4013 4014 |
# File 'lib/syntax_tree/node.rb', line 4012 def statements @statements end |
Instance Method Details
#accept(visitor) ⇒ Object
4024 4025 4026 |
# File 'lib/syntax_tree/node.rb', line 4024 def accept(visitor) visitor.visit_else(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
4028 4029 4030 |
# File 'lib/syntax_tree/node.rb', line 4028 def child_nodes [keyword, statements] end |
#deconstruct_keys(_keys) ⇒ Object
4034 4035 4036 4037 4038 4039 4040 4041 |
# File 'lib/syntax_tree/node.rb', line 4034 def deconstruct_keys(_keys) { keyword: keyword, statements: statements, location: location, comments: comments } end |
#format(q) ⇒ Object
4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 |
# File 'lib/syntax_tree/node.rb', line 4043 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 |