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.



7594
7595
7596
7597
7598
7599
# File 'lib/syntax_tree/node.rb', line 7594

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



7592
7593
7594
# File 'lib/syntax_tree/node.rb', line 7592

def comments
  @comments
end

#exceptionsObject (readonly)

untyped

the list of exceptions being rescued



7585
7586
7587
# File 'lib/syntax_tree/node.rb', line 7585

def exceptions
  @exceptions
end

#variableObject (readonly)

nil | Field | VarField

the expression being used to capture the raised

exception



7589
7590
7591
# File 'lib/syntax_tree/node.rb', line 7589

def variable
  @variable
end

Instance Method Details

#accept(visitor) ⇒ Object



7601
7602
7603
# File 'lib/syntax_tree/node.rb', line 7601

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

#child_nodesObject Also known as: deconstruct



7605
7606
7607
# File 'lib/syntax_tree/node.rb', line 7605

def child_nodes
  [*exceptions, variable]
end

#deconstruct_keys(_keys) ⇒ Object



7611
7612
7613
7614
7615
7616
7617
7618
# File 'lib/syntax_tree/node.rb', line 7611

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

#format(q) ⇒ Object



7620
7621
7622
7623
7624
7625
7626
7627
7628
7629
7630
7631
7632
# File 'lib/syntax_tree/node.rb', line 7620

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

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