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.



7636
7637
7638
7639
7640
7641
# File 'lib/syntax_tree/node.rb', line 7636

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



7634
7635
7636
# File 'lib/syntax_tree/node.rb', line 7634

def comments
  @comments
end

#exceptionsObject (readonly)

untyped

the list of exceptions being rescued



7627
7628
7629
# File 'lib/syntax_tree/node.rb', line 7627

def exceptions
  @exceptions
end

#variableObject (readonly)

nil | Field | VarField

the expression being used to capture the raised

exception



7631
7632
7633
# File 'lib/syntax_tree/node.rb', line 7631

def variable
  @variable
end

Instance Method Details

#accept(visitor) ⇒ Object



7643
7644
7645
# File 'lib/syntax_tree/node.rb', line 7643

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

#child_nodesObject Also known as: deconstruct



7647
7648
7649
# File 'lib/syntax_tree/node.rb', line 7647

def child_nodes
  [*exceptions, variable]
end

#deconstruct_keys(_keys) ⇒ Object



7653
7654
7655
7656
7657
7658
7659
7660
# File 'lib/syntax_tree/node.rb', line 7653

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

#format(q) ⇒ Object



7662
7663
7664
7665
7666
7667
7668
7669
7670
7671
7672
7673
7674
# File 'lib/syntax_tree/node.rb', line 7662

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

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