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
- #===(other) ⇒ Object
- #accept(visitor) ⇒ Object
- #child_nodes ⇒ Object (also: #deconstruct)
- #copy(keyword: nil, statements: nil, location: nil) ⇒ Object
- #deconstruct_keys(_keys) ⇒ Object
- #format(q) ⇒ Object
-
#initialize(keyword:, statements:, location:) ⇒ Ensure
constructor
A new instance of Ensure.
Methods inherited from Node
#construct_keys, #end_char, #pretty_print, #start_char, #to_json, #to_mermaid
Constructor Details
#initialize(keyword:, statements:, location:) ⇒ Ensure
Returns a new instance of Ensure.
5171 5172 5173 5174 5175 5176 |
# File 'lib/syntax_tree/node.rb', line 5171 def initialize(keyword:, statements:, location:) @keyword = keyword @statements = statements @location = location @comments = [] end |
Instance Attribute Details
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
5169 5170 5171 |
# File 'lib/syntax_tree/node.rb', line 5169 def comments @comments end |
#keyword ⇒ Object (readonly)
- Kw
-
the ensure keyword that began this node
5163 5164 5165 |
# File 'lib/syntax_tree/node.rb', line 5163 def keyword @keyword end |
#statements ⇒ Object (readonly)
- Statements
-
the expressions to be executed
5166 5167 5168 |
# File 'lib/syntax_tree/node.rb', line 5166 def statements @statements end |
Instance Method Details
#===(other) ⇒ Object
5220 5221 5222 5223 |
# File 'lib/syntax_tree/node.rb', line 5220 def ===(other) other.is_a?(Ensure) && keyword === other.keyword && statements === other.statements end |
#accept(visitor) ⇒ Object
5178 5179 5180 |
# File 'lib/syntax_tree/node.rb', line 5178 def accept(visitor) visitor.visit_ensure(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
5182 5183 5184 |
# File 'lib/syntax_tree/node.rb', line 5182 def child_nodes [keyword, statements] end |
#copy(keyword: nil, statements: nil, location: nil) ⇒ Object
5186 5187 5188 5189 5190 5191 5192 5193 5194 5195 5196 |
# File 'lib/syntax_tree/node.rb', line 5186 def copy(keyword: nil, statements: nil, location: nil) node = Ensure.new( keyword: keyword || self.keyword, statements: statements || self.statements, location: location || self.location ) node.comments.concat(comments.map(&:copy)) node end |
#deconstruct_keys(_keys) ⇒ Object
5200 5201 5202 5203 5204 5205 5206 5207 |
# File 'lib/syntax_tree/node.rb', line 5200 def deconstruct_keys(_keys) { keyword: keyword, statements: statements, location: location, comments: comments } end |
#format(q) ⇒ Object
5209 5210 5211 5212 5213 5214 5215 5216 5217 5218 |
# File 'lib/syntax_tree/node.rb', line 5209 def format(q) q.format(keyword) unless statements.empty? q.indent do q.breakable_force q.format(statements) end end end |