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.
5680 5681 5682 5683 5684 5685 |
# File 'lib/syntax_tree.rb', line 5680 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
5678 5679 5680 |
# File 'lib/syntax_tree.rb', line 5678 def comments @comments end |
#keyword ⇒ Object (readonly)
- Kw
-
the ensure keyword that began this node
5669 5670 5671 |
# File 'lib/syntax_tree.rb', line 5669 def keyword @keyword end |
#location ⇒ Object (readonly)
- Location
-
the location of this node
5675 5676 5677 |
# File 'lib/syntax_tree.rb', line 5675 def location @location end |
#statements ⇒ Object (readonly)
- Statements
-
the expressions to be executed
5672 5673 5674 |
# File 'lib/syntax_tree.rb', line 5672 def statements @statements end |
Instance Method Details
#child_nodes ⇒ Object
5687 5688 5689 |
# File 'lib/syntax_tree.rb', line 5687 def child_nodes [keyword, statements] end |
#format(q) ⇒ Object
5691 5692 5693 5694 5695 5696 5697 5698 5699 5700 |
# File 'lib/syntax_tree.rb', line 5691 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
5702 5703 5704 5705 5706 5707 5708 5709 5710 5711 |
# File 'lib/syntax_tree.rb', line 5702 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
5713 5714 5715 5716 5717 5718 5719 5720 5721 |
# File 'lib/syntax_tree.rb', line 5713 def to_json(*opts) { type: :ensure, keyword: keyword, stmts: statements, loc: location, cmts: comments }.to_json(*opts) end |