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
Returns a new instance of Ensure.
5643 5644 5645 5646 5647 5648 |
# File 'lib/syntax_tree.rb', line 5643 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
5641 5642 5643 |
# File 'lib/syntax_tree.rb', line 5641 def comments @comments end |
#keyword ⇒ Object (readonly)
- Kw
-
the ensure keyword that began this node
5632 5633 5634 |
# File 'lib/syntax_tree.rb', line 5632 def keyword @keyword end |
#location ⇒ Object (readonly)
- Location
-
the location of this node
5638 5639 5640 |
# File 'lib/syntax_tree.rb', line 5638 def location @location end |
#statements ⇒ Object (readonly)
- Statements
-
the expressions to be executed
5635 5636 5637 |
# File 'lib/syntax_tree.rb', line 5635 def statements @statements end |
Instance Method Details
#child_nodes ⇒ Object
5650 5651 5652 |
# File 'lib/syntax_tree.rb', line 5650 def child_nodes [keyword, statements] end |
#format(q) ⇒ Object
5654 5655 5656 5657 5658 5659 5660 5661 5662 5663 |
# File 'lib/syntax_tree.rb', line 5654 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
5665 5666 5667 5668 5669 5670 5671 5672 5673 5674 |
# File 'lib/syntax_tree.rb', line 5665 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
5676 5677 5678 5679 5680 5681 5682 5683 5684 |
# File 'lib/syntax_tree.rb', line 5676 def to_json(*opts) { type: :ensure, keyword: keyword, stmts: statements, loc: location, cmts: comments }.to_json(*opts) end |