class SyntaxTree::Rescue

Rescue represents the use of the rescue keyword inside of a BodyStmt node.

begin
rescue
end

Attributes

comments[R]
Array[ Comment | EmbDoc ]

the comments attached to this node

consequent[R]
nil | Rescue

the optional next clause in the chain

exception[R]
nil | RescueEx

the exceptions being rescued

keyword[R]
Kw

the rescue keyword

statements[R]
Statements

the expressions to evaluate when an error is rescued

Public Class Methods

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

Public Instance Methods

===(other) click to toggle source
# File lib/syntax_tree/node.rb, line 9520
def ===(other)
  other.is_a?(Rescue) && keyword === other.keyword &&
    exception === other.exception && statements === other.statements &&
    consequent === other.consequent
end
accept(visitor) click to toggle source
# File lib/syntax_tree/node.rb, line 9455
def accept(visitor)
  visitor.visit_rescue(self)
end
bind_end(end_char, end_column) click to toggle source
# File lib/syntax_tree/node.rb, line 9433
def bind_end(end_char, end_column)
  @location =
    Location.new(
      start_line: location.start_line,
      start_char: location.start_char,
      start_column: location.start_column,
      end_line: location.end_line,
      end_char: end_char,
      end_column: end_column
    )

  if (next_node = consequent)
    next_node.bind_end(end_char, end_column)
    statements.bind_end(
      next_node.location.start_char,
      next_node.location.start_column
    )
  else
    statements.bind_end(end_char, end_column)
  end
end
child_nodes() click to toggle source
# File lib/syntax_tree/node.rb, line 9459
def child_nodes
  [keyword, exception, statements, consequent]
end
Also aliased as: deconstruct
copy( keyword: nil, exception: nil, statements: nil, consequent: nil, location: nil ) click to toggle source
# File lib/syntax_tree/node.rb, line 9463
def copy(
  keyword: nil,
  exception: nil,
  statements: nil,
  consequent: nil,
  location: nil
)
  node =
    Rescue.new(
      keyword: keyword || self.keyword,
      exception: exception || self.exception,
      statements: statements || self.statements,
      consequent: consequent || self.consequent,
      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 9485
def deconstruct_keys(_keys)
  {
    keyword: keyword,
    exception: exception,
    statements: statements,
    consequent: consequent,
    location: location,
    comments: comments
  }
end
format(q) click to toggle source
# File lib/syntax_tree/node.rb, line 9496
def format(q)
  q.group do
    q.format(keyword)

    if exception
      q.nest(keyword.value.length + 1) { q.format(exception) }
    else
      q.text(" StandardError")
    end

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

    if consequent
      q.breakable_force
      q.format(consequent)
    end
  end
end