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

#pretty_print, #to_json

Constructor Details

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

Returns a new instance of RescueEx.



6833
6834
6835
6836
6837
6838
# File 'lib/syntax_tree/node.rb', line 6833

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



6831
6832
6833
# File 'lib/syntax_tree/node.rb', line 6831

def comments
  @comments
end

#exceptionsObject (readonly)

untyped

the list of exceptions being rescued



6824
6825
6826
# File 'lib/syntax_tree/node.rb', line 6824

def exceptions
  @exceptions
end

#variableObject (readonly)

nil | Field | VarField

the expression being used to capture the raised

exception



6828
6829
6830
# File 'lib/syntax_tree/node.rb', line 6828

def variable
  @variable
end

Instance Method Details

#accept(visitor) ⇒ Object



6840
6841
6842
# File 'lib/syntax_tree/node.rb', line 6840

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

#child_nodesObject Also known as: deconstruct



6844
6845
6846
# File 'lib/syntax_tree/node.rb', line 6844

def child_nodes
  [*exceptions, variable]
end

#deconstruct_keys(keys) ⇒ Object



6850
6851
6852
6853
6854
6855
6856
6857
# File 'lib/syntax_tree/node.rb', line 6850

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

#format(q) ⇒ Object



6859
6860
6861
6862
6863
6864
6865
6866
6867
6868
6869
6870
6871
# File 'lib/syntax_tree/node.rb', line 6859

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

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