Class: SyntaxTree::Ensure
- Inherits:
-
Node
- Object
- Node
- SyntaxTree::Ensure
show all
- Defined in:
- lib/syntax_tree/node.rb
Overview
Ensure represents the use of the ensure keyword and its subsequent
statements.
begin
ensure
end
Instance Attribute Summary collapse
Attributes inherited from Node
#location
Instance Method Summary
collapse
Methods inherited from Node
#construct_keys, #end_char, #pretty_print, #start_char, #to_json, #to_mermaid
Constructor Details
#initialize(keyword:, statements:, location:) ⇒ Ensure
5189
5190
5191
5192
5193
5194
|
# File 'lib/syntax_tree/node.rb', line 5189
def initialize(keyword:, statements:, location:)
@keyword = keyword
@statements = statements
@location = location
= []
end
|
Instance Attribute Details
[Array[ Comment | EmbDoc ]] the comments attached to this node
5187
5188
5189
|
# File 'lib/syntax_tree/node.rb', line 5187
def
end
|
#keyword ⇒ Object
[Kw] the ensure keyword that began this node
5181
5182
5183
|
# File 'lib/syntax_tree/node.rb', line 5181
def keyword
@keyword
end
|
#statements ⇒ Object
[Statements] the expressions to be executed
5184
5185
5186
|
# File 'lib/syntax_tree/node.rb', line 5184
def statements
@statements
end
|
Instance Method Details
#===(other) ⇒ Object
5238
5239
5240
5241
|
# File 'lib/syntax_tree/node.rb', line 5238
def ===(other)
other.is_a?(Ensure) && keyword === other.keyword &&
statements === other.statements
end
|
#accept(visitor) ⇒ Object
5196
5197
5198
|
# File 'lib/syntax_tree/node.rb', line 5196
def accept(visitor)
visitor.visit_ensure(self)
end
|
#child_nodes ⇒ Object
Also known as:
deconstruct
5200
5201
5202
|
# File 'lib/syntax_tree/node.rb', line 5200
def child_nodes
[keyword, statements]
end
|
#copy(keyword: nil, statements: nil, location: nil) ⇒ Object
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
|
# File 'lib/syntax_tree/node.rb', line 5204
def copy(keyword: nil, statements: nil, location: nil)
node =
Ensure.new(
keyword: keyword || self.keyword,
statements: statements || self.statements,
location: location || self.location
)
node..concat(.map(&:copy))
node
end
|
#deconstruct_keys(_keys) ⇒ Object
5218
5219
5220
5221
5222
5223
5224
5225
|
# File 'lib/syntax_tree/node.rb', line 5218
def deconstruct_keys(_keys)
{
keyword: keyword,
statements: statements,
location: location,
comments:
}
end
|
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
|
# File 'lib/syntax_tree/node.rb', line 5227
def format(q)
q.format(keyword)
unless statements.empty?
q.indent do
q.breakable_force
q.format(statements)
end
end
end
|