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.



7846
7847
7848
7849
7850
7851
# File 'lib/syntax_tree/node.rb', line 7846

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



7844
7845
7846
# File 'lib/syntax_tree/node.rb', line 7844

def comments
  @comments
end

#exceptionsObject (readonly)

untyped

the list of exceptions being rescued



7837
7838
7839
# File 'lib/syntax_tree/node.rb', line 7837

def exceptions
  @exceptions
end

#variableObject (readonly)

nil | Field | VarField

the expression being used to capture the raised

exception



7841
7842
7843
# File 'lib/syntax_tree/node.rb', line 7841

def variable
  @variable
end

Instance Method Details

#accept(visitor) ⇒ Object



7853
7854
7855
# File 'lib/syntax_tree/node.rb', line 7853

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

#child_nodesObject Also known as: deconstruct



7857
7858
7859
# File 'lib/syntax_tree/node.rb', line 7857

def child_nodes
  [*exceptions, variable]
end

#deconstruct_keys(_keys) ⇒ Object



7863
7864
7865
7866
7867
7868
7869
7870
# File 'lib/syntax_tree/node.rb', line 7863

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

#format(q) ⇒ Object



7872
7873
7874
7875
7876
7877
7878
7879
7880
7881
7882
7883
7884
# File 'lib/syntax_tree/node.rb', line 7872

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

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