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
- #accept(visitor) ⇒ Object
- #child_nodes ⇒ Object (also: #deconstruct)
- #deconstruct_keys(_keys) ⇒ Object
- #format(q) ⇒ Object
-
#initialize(keyword:, statements:, location:, comments: []) ⇒ Ensure
constructor
A new instance of Ensure.
Methods inherited from Node
#construct_keys, #pretty_print, #to_json
Constructor Details
#initialize(keyword:, statements:, location:, comments: []) ⇒ Ensure
Returns a new instance of Ensure.
4329 4330 4331 4332 4333 4334 |
# File 'lib/syntax_tree/node.rb', line 4329 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
4327 4328 4329 |
# File 'lib/syntax_tree/node.rb', line 4327 def comments @comments end |
#keyword ⇒ Object (readonly)
- Kw
-
the ensure keyword that began this node
4321 4322 4323 |
# File 'lib/syntax_tree/node.rb', line 4321 def keyword @keyword end |
#statements ⇒ Object (readonly)
- Statements
-
the expressions to be executed
4324 4325 4326 |
# File 'lib/syntax_tree/node.rb', line 4324 def statements @statements end |
Instance Method Details
#accept(visitor) ⇒ Object
4336 4337 4338 |
# File 'lib/syntax_tree/node.rb', line 4336 def accept(visitor) visitor.visit_ensure(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
4340 4341 4342 |
# File 'lib/syntax_tree/node.rb', line 4340 def child_nodes [keyword, statements] end |
#deconstruct_keys(_keys) ⇒ Object
4346 4347 4348 4349 4350 4351 4352 4353 |
# File 'lib/syntax_tree/node.rb', line 4346 def deconstruct_keys(_keys) { keyword: keyword, statements: statements, location: location, comments: comments } end |
#format(q) ⇒ Object
4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 |
# File 'lib/syntax_tree/node.rb', line 4355 def format(q) q.format(keyword) unless statements.empty? q.indent do q.breakable(force: true) q.format(statements) end end end |