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.
4257 4258 4259 4260 4261 4262 |
# File 'lib/syntax_tree/node.rb', line 4257 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
4255 4256 4257 |
# File 'lib/syntax_tree/node.rb', line 4255 def comments @comments end |
#keyword ⇒ Object (readonly)
- Kw
-
the ensure keyword that began this node
4249 4250 4251 |
# File 'lib/syntax_tree/node.rb', line 4249 def keyword @keyword end |
#statements ⇒ Object (readonly)
- Statements
-
the expressions to be executed
4252 4253 4254 |
# File 'lib/syntax_tree/node.rb', line 4252 def statements @statements end |
Instance Method Details
#accept(visitor) ⇒ Object
4264 4265 4266 |
# File 'lib/syntax_tree/node.rb', line 4264 def accept(visitor) visitor.visit_ensure(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
4268 4269 4270 |
# File 'lib/syntax_tree/node.rb', line 4268 def child_nodes [keyword, statements] end |
#deconstruct_keys(_keys) ⇒ Object
4274 4275 4276 4277 4278 4279 4280 4281 |
# File 'lib/syntax_tree/node.rb', line 4274 def deconstruct_keys(_keys) { keyword: keyword, statements: statements, location: location, comments: comments } end |
#format(q) ⇒ Object
4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 |
# File 'lib/syntax_tree/node.rb', line 4283 def format(q) q.format(keyword) unless statements.empty? q.indent do q.breakable(force: true) q.format(statements) end end end |