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.
5812 5813 5814 5815 5816 5817 |
# File 'lib/syntax_tree.rb', line 5812 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
5810 5811 5812 |
# File 'lib/syntax_tree.rb', line 5810 def comments @comments end |
#keyword ⇒ Object (readonly)
- Kw
-
the ensure keyword that began this node
5801 5802 5803 |
# File 'lib/syntax_tree.rb', line 5801 def keyword @keyword end |
#location ⇒ Object (readonly)
- Location
-
the location of this node
5807 5808 5809 |
# File 'lib/syntax_tree.rb', line 5807 def location @location end |
#statements ⇒ Object (readonly)
- Statements
-
the expressions to be executed
5804 5805 5806 |
# File 'lib/syntax_tree.rb', line 5804 def statements @statements end |
Instance Method Details
#child_nodes ⇒ Object
5819 5820 5821 |
# File 'lib/syntax_tree.rb', line 5819 def child_nodes [keyword, statements] end |
#format(q) ⇒ Object
5823 5824 5825 5826 5827 5828 5829 5830 5831 5832 |
# File 'lib/syntax_tree.rb', line 5823 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
5834 5835 5836 5837 5838 5839 5840 5841 5842 5843 |
# File 'lib/syntax_tree.rb', line 5834 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
5845 5846 5847 5848 5849 5850 5851 5852 5853 |
# File 'lib/syntax_tree.rb', line 5845 def to_json(*opts) { type: :ensure, keyword: keyword, stmts: statements, loc: location, cmts: comments }.to_json(*opts) end |