Class: SyntaxTree::Ensure
Overview
Ensure represents the use of the ensure keyword and its subsequent statements.
begin
ensure
end
Instance Attribute Summary collapse
-
#comments ⇒ Object
readonly
- Array[ Comment | EmbDoc ]
-
the comments attached to this node.
-
#keyword ⇒ Object
readonly
- Kw
-
the ensure keyword that began this node.
-
#statements ⇒ Object
readonly
- Statements
-
the expressions to be executed.
Attributes inherited from Node
Instance Method Summary collapse
- #===(other) ⇒ Object
- #accept(visitor) ⇒ Object
- #child_nodes ⇒ Object (also: #deconstruct)
- #copy(keyword: nil, statements: nil, location: nil) ⇒ Object
- #deconstruct_keys(_keys) ⇒ Object
- #format(q) ⇒ Object
-
#initialize(keyword:, statements:, location:) ⇒ Ensure
constructor
A new instance of Ensure.
Methods inherited from Node
#construct_keys, #end_char, #pretty_print, #start_char, #to_json, #to_mermaid
Constructor Details
#initialize(keyword:, statements:, location:) ⇒ Ensure
Returns a new instance of 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 @comments = [] end |
Instance Attribute Details
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
5187 5188 5189 |
# File 'lib/syntax_tree/node.rb', line 5187 def comments @comments end |
#keyword ⇒ Object (readonly)
- 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 (readonly)
- 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.comments.concat(comments.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: comments } end |
#format(q) ⇒ Object
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 |