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.
4438 4439 4440 4441 4442 4443 |
# File 'lib/syntax_tree/node.rb', line 4438 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
4436 4437 4438 |
# File 'lib/syntax_tree/node.rb', line 4436 def comments @comments end |
#keyword ⇒ Object (readonly)
- Kw
-
the ensure keyword that began this node
4430 4431 4432 |
# File 'lib/syntax_tree/node.rb', line 4430 def keyword @keyword end |
#statements ⇒ Object (readonly)
- Statements
-
the expressions to be executed
4433 4434 4435 |
# File 'lib/syntax_tree/node.rb', line 4433 def statements @statements end |
Instance Method Details
#accept(visitor) ⇒ Object
4445 4446 4447 |
# File 'lib/syntax_tree/node.rb', line 4445 def accept(visitor) visitor.visit_ensure(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
4449 4450 4451 |
# File 'lib/syntax_tree/node.rb', line 4449 def child_nodes [keyword, statements] end |
#deconstruct_keys(_keys) ⇒ Object
4455 4456 4457 4458 4459 4460 4461 4462 |
# File 'lib/syntax_tree/node.rb', line 4455 def deconstruct_keys(_keys) { keyword: keyword, statements: statements, location: location, comments: comments } end |
#format(q) ⇒ Object
4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 |
# File 'lib/syntax_tree/node.rb', line 4464 def format(q) q.format(keyword) unless statements.empty? q.indent do q.breakable_force q.format(statements) end end end |