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.
5122 5123 5124 5125 5126 5127 |
# File 'lib/syntax_tree/node.rb', line 5122 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
5120 5121 5122 |
# File 'lib/syntax_tree/node.rb', line 5120 def comments @comments end |
#keyword ⇒ Object (readonly)
- Kw
-
the ensure keyword that began this node
5114 5115 5116 |
# File 'lib/syntax_tree/node.rb', line 5114 def keyword @keyword end |
#statements ⇒ Object (readonly)
- Statements
-
the expressions to be executed
5117 5118 5119 |
# File 'lib/syntax_tree/node.rb', line 5117 def statements @statements end |
Instance Method Details
#===(other) ⇒ Object
5171 5172 5173 5174 |
# File 'lib/syntax_tree/node.rb', line 5171 def ===(other) other.is_a?(Ensure) && keyword === other.keyword && statements === other.statements end |
#accept(visitor) ⇒ Object
5129 5130 5131 |
# File 'lib/syntax_tree/node.rb', line 5129 def accept(visitor) visitor.visit_ensure(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
5133 5134 5135 |
# File 'lib/syntax_tree/node.rb', line 5133 def child_nodes [keyword, statements] end |
#copy(keyword: nil, statements: nil, location: nil) ⇒ Object
5137 5138 5139 5140 5141 5142 5143 5144 5145 5146 5147 |
# File 'lib/syntax_tree/node.rb', line 5137 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
5151 5152 5153 5154 5155 5156 5157 5158 |
# File 'lib/syntax_tree/node.rb', line 5151 def deconstruct_keys(_keys) { keyword: keyword, statements: statements, location: location, comments: comments } end |
#format(q) ⇒ Object
5160 5161 5162 5163 5164 5165 5166 5167 5168 5169 |
# File 'lib/syntax_tree/node.rb', line 5160 def format(q) q.format(keyword) unless statements.empty? q.indent do q.breakable_force q.format(statements) end end end |