Class: SyntaxTree::Ensure
- Inherits:
-
Object
- Object
- SyntaxTree::Ensure
- Defined in:
- lib/syntax_tree.rb
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.
-
#location ⇒ Object
readonly
- Location
-
the location of this node.
-
#statements ⇒ Object
readonly
- Statements
-
the expressions to be executed.
Instance Method Summary collapse
- #child_nodes ⇒ Object
- #format(q) ⇒ Object
-
#initialize(keyword:, statements:, location:, comments: []) ⇒ Ensure
constructor
A new instance of Ensure.
- #pretty_print(q) ⇒ Object
- #to_json(*opts) ⇒ Object
Constructor Details
#initialize(keyword:, statements:, location:, comments: []) ⇒ Ensure
5342 5343 5344 5345 5346 5347 |
# File 'lib/syntax_tree.rb', line 5342 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
5340 5341 5342 |
# File 'lib/syntax_tree.rb', line 5340 def comments @comments end |
#keyword ⇒ Object (readonly)
- Kw
-
the ensure keyword that began this node
5331 5332 5333 |
# File 'lib/syntax_tree.rb', line 5331 def keyword @keyword end |
#location ⇒ Object (readonly)
- Location
-
the location of this node
5337 5338 5339 |
# File 'lib/syntax_tree.rb', line 5337 def location @location end |
#statements ⇒ Object (readonly)
- Statements
-
the expressions to be executed
5334 5335 5336 |
# File 'lib/syntax_tree.rb', line 5334 def statements @statements end |
Instance Method Details
#child_nodes ⇒ Object
5349 5350 5351 |
# File 'lib/syntax_tree.rb', line 5349 def child_nodes [keyword, statements] end |
#format(q) ⇒ Object
5353 5354 5355 5356 5357 5358 5359 5360 5361 5362 |
# File 'lib/syntax_tree.rb', line 5353 def format(q) q.format(keyword) unless statements.empty? q.indent do q.breakable(force: true) q.format(statements) end end end |
#pretty_print(q) ⇒ Object
5364 5365 5366 5367 5368 5369 5370 5371 5372 5373 |
# File 'lib/syntax_tree.rb', line 5364 def pretty_print(q) q.group(2, "(", ")") do q.text("ensure") q.breakable q.pp(statements) q.pp(Comment::List.new(comments)) end end |
#to_json(*opts) ⇒ Object
5375 5376 5377 5378 5379 5380 5381 5382 5383 |
# File 'lib/syntax_tree.rb', line 5375 def to_json(*opts) { type: :ensure, keyword: keyword, stmts: statements, loc: location, cmts: comments }.to_json(*opts) end |