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
5153
5154
5155
5156
5157
5158
|
# File 'lib/syntax_tree/node.rb', line 5153
def initialize(keyword:, statements:, location:)
@keyword = keyword
@statements = statements
@location = location
= []
end
|
Instance Attribute Details
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
5151
5152
5153
|
# File 'lib/syntax_tree/node.rb', line 5151
def
end
|
#keyword ⇒ Object
- Kw
-
the ensure keyword that began this node
5145
5146
5147
|
# File 'lib/syntax_tree/node.rb', line 5145
def keyword
@keyword
end
|
#statements ⇒ Object
- Statements
-
the expressions to be executed
5148
5149
5150
|
# File 'lib/syntax_tree/node.rb', line 5148
def statements
@statements
end
|
Instance Method Details
#===(other) ⇒ Object
5202
5203
5204
5205
|
# File 'lib/syntax_tree/node.rb', line 5202
def ===(other)
other.is_a?(Ensure) && keyword === other.keyword &&
statements === other.statements
end
|
#accept(visitor) ⇒ Object
5160
5161
5162
|
# File 'lib/syntax_tree/node.rb', line 5160
def accept(visitor)
visitor.visit_ensure(self)
end
|
#child_nodes ⇒ Object
Also known as:
deconstruct
5164
5165
5166
|
# File 'lib/syntax_tree/node.rb', line 5164
def child_nodes
[keyword, statements]
end
|
#copy(keyword: nil, statements: nil, location: nil) ⇒ Object
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
|
# File 'lib/syntax_tree/node.rb', line 5168
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
5182
5183
5184
5185
5186
5187
5188
5189
|
# File 'lib/syntax_tree/node.rb', line 5182
def deconstruct_keys(_keys)
{
keyword: keyword,
statements: statements,
location: location,
comments:
}
end
|
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
|
# File 'lib/syntax_tree/node.rb', line 5191
def format(q)
q.format(keyword)
unless statements.empty?
q.indent do
q.breakable_force
q.format(statements)
end
end
end
|