Class: SyntaxTree::RescueEx

Inherits:
Node
  • Object
show all
Defined in:
lib/syntax_tree/node.rb

Overview

RescueEx represents the list of exceptions being rescued in a rescue clause.

begin
rescue Exception => exception
end

Instance Attribute Summary collapse

Attributes inherited from Node

#location

Instance Method Summary collapse

Methods inherited from Node

#construct_keys, #pretty_print, #to_json

Constructor Details

#initialize(exceptions:, variable:, location:, comments: []) ⇒ RescueEx

Returns a new instance of RescueEx.



7472
7473
7474
7475
7476
7477
# File 'lib/syntax_tree/node.rb', line 7472

def initialize(exceptions:, variable:, location:, comments: [])
  @exceptions = exceptions
  @variable = variable
  @location = location
  @comments = comments
end

Instance Attribute Details

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



7470
7471
7472
# File 'lib/syntax_tree/node.rb', line 7470

def comments
  @comments
end

#exceptionsObject (readonly)

untyped

the list of exceptions being rescued



7463
7464
7465
# File 'lib/syntax_tree/node.rb', line 7463

def exceptions
  @exceptions
end

#variableObject (readonly)

nil | Field | VarField

the expression being used to capture the raised

exception



7467
7468
7469
# File 'lib/syntax_tree/node.rb', line 7467

def variable
  @variable
end

Instance Method Details

#accept(visitor) ⇒ Object



7479
7480
7481
# File 'lib/syntax_tree/node.rb', line 7479

def accept(visitor)
  visitor.visit_rescue_ex(self)
end

#child_nodesObject Also known as: deconstruct



7483
7484
7485
# File 'lib/syntax_tree/node.rb', line 7483

def child_nodes
  [*exceptions, variable]
end

#deconstruct_keys(_keys) ⇒ Object



7489
7490
7491
7492
7493
7494
7495
7496
# File 'lib/syntax_tree/node.rb', line 7489

def deconstruct_keys(_keys)
  {
    exceptions: exceptions,
    variable: variable,
    location: location,
    comments: comments
  }
end

#format(q) ⇒ Object



7498
7499
7500
7501
7502
7503
7504
7505
7506
7507
7508
7509
7510
# File 'lib/syntax_tree/node.rb', line 7498

def format(q)
  q.group do
    if exceptions
      q.text(" ")
      q.format(exceptions)
    end

    if variable
      q.text(" => ")
      q.format(variable)
    end
  end
end