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
4164 4165 4166 4167 4168 4169 |
# File 'lib/syntax_tree/node.rb', line 4164 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
4162 4163 4164 |
# File 'lib/syntax_tree/node.rb', line 4162 def comments @comments end |
#keyword ⇒ Object (readonly)
- Kw
-
the else keyword
4156 4157 4158 |
# File 'lib/syntax_tree/node.rb', line 4156 def keyword @keyword end |
#statements ⇒ Object (readonly)
- Statements
-
the expressions to be executed
4159 4160 4161 |
# File 'lib/syntax_tree/node.rb', line 4159 def statements @statements end |
Instance Method Details
#accept(visitor) ⇒ Object
4171 4172 4173 |
# File 'lib/syntax_tree/node.rb', line 4171 def accept(visitor) visitor.visit_else(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
4175 4176 4177 |
# File 'lib/syntax_tree/node.rb', line 4175 def child_nodes [keyword, statements] end |
#deconstruct_keys(_keys) ⇒ Object
4181 4182 4183 4184 4185 4186 4187 4188 |
# File 'lib/syntax_tree/node.rb', line 4181 def deconstruct_keys(_keys) { keyword: keyword, statements: statements, location: location, comments: comments } end |
#format(q) ⇒ Object
4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 |
# File 'lib/syntax_tree/node.rb', line 4190 def format(q) q.group do q.format(keyword) unless statements.empty? q.indent do q.breakable_force q.format(statements) end end end end |