class SyntaxTree::Ensure

Ensure represents the use of the ensure keyword and its subsequent statements.

begin
ensure
end

Attributes

comments[R]
Array[ Comment | EmbDoc ]

the comments attached to this node

keyword[R]
Kw

the ensure keyword that began this node

statements[R]
Statements

the expressions to be executed

Public Class Methods

new(keyword:, statements:, location:) click to toggle source
# File lib/syntax_tree/node.rb, line 5174
def initialize(keyword:, statements:, location:)
  @keyword = keyword
  @statements = statements
  @location = location
  @comments = []
end

Public Instance Methods

===(other) click to toggle source
# File lib/syntax_tree/node.rb, line 5223
def ===(other)
  other.is_a?(Ensure) && keyword === other.keyword &&
    statements === other.statements
end
accept(visitor) click to toggle source
# File lib/syntax_tree/node.rb, line 5181
def accept(visitor)
  visitor.visit_ensure(self)
end
child_nodes() click to toggle source
# File lib/syntax_tree/node.rb, line 5185
def child_nodes
  [keyword, statements]
end
Also aliased as: deconstruct
copy(keyword: nil, statements: nil, location: nil) click to toggle source
# File lib/syntax_tree/node.rb, line 5189
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()
Alias for: child_nodes
deconstruct_keys(_keys) click to toggle source
# File lib/syntax_tree/node.rb, line 5203
def deconstruct_keys(_keys)
  {
    keyword: keyword,
    statements: statements,
    location: location,
    comments: comments
  }
end
format(q) click to toggle source
# File lib/syntax_tree/node.rb, line 5212
def format(q)
  q.format(keyword)

  unless statements.empty?
    q.indent do
      q.breakable_force
      q.format(statements)
    end
  end
end