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, #pretty_print, #to_json
Constructor Details
#initialize(keyword:, statements:, location:) ⇒ Ensure
Returns a new instance of Ensure.
5067 5068 5069 5070 5071 5072 |
# File 'lib/syntax_tree/node.rb', line 5067 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
5065 5066 5067 |
# File 'lib/syntax_tree/node.rb', line 5065 def comments @comments end |
#keyword ⇒ Object (readonly)
- Kw
-
the ensure keyword that began this node
5059 5060 5061 |
# File 'lib/syntax_tree/node.rb', line 5059 def keyword @keyword end |
#statements ⇒ Object (readonly)
- Statements
-
the expressions to be executed
5062 5063 5064 |
# File 'lib/syntax_tree/node.rb', line 5062 def statements @statements end |
Instance Method Details
#===(other) ⇒ Object
5116 5117 5118 5119 |
# File 'lib/syntax_tree/node.rb', line 5116 def ===(other) other.is_a?(Ensure) && keyword === other.keyword && statements === other.statements end |
#accept(visitor) ⇒ Object
5074 5075 5076 |
# File 'lib/syntax_tree/node.rb', line 5074 def accept(visitor) visitor.visit_ensure(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
5078 5079 5080 |
# File 'lib/syntax_tree/node.rb', line 5078 def child_nodes [keyword, statements] end |
#copy(keyword: nil, statements: nil, location: nil) ⇒ Object
5082 5083 5084 5085 5086 5087 5088 5089 5090 5091 5092 |
# File 'lib/syntax_tree/node.rb', line 5082 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
5096 5097 5098 5099 5100 5101 5102 5103 |
# File 'lib/syntax_tree/node.rb', line 5096 def deconstruct_keys(_keys) { keyword: keyword, statements: statements, location: location, comments: comments } end |
#format(q) ⇒ Object
5105 5106 5107 5108 5109 5110 5111 5112 5113 5114 |
# File 'lib/syntax_tree/node.rb', line 5105 def format(q) q.format(keyword) unless statements.empty? q.indent do q.breakable_force q.format(statements) end end end |