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:) ⇒ RescueEx



9205
9206
9207
9208
9209
9210
# File 'lib/syntax_tree/node.rb', line 9205

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

Instance Attribute Details

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



9203
9204
9205
# File 'lib/syntax_tree/node.rb', line 9203

def comments
  @comments
end

#exceptionsObject (readonly)

untyped

the list of exceptions being rescued



9196
9197
9198
# File 'lib/syntax_tree/node.rb', line 9196

def exceptions
  @exceptions
end

#variableObject (readonly)

nil | Field | VarField

the expression being used to capture the raised

exception



9200
9201
9202
# File 'lib/syntax_tree/node.rb', line 9200

def variable
  @variable
end

Instance Method Details

#===(other) ⇒ Object



9257
9258
9259
9260
# File 'lib/syntax_tree/node.rb', line 9257

def ===(other)
  other.is_a?(RescueEx) && exceptions === other.exceptions &&
    variable === other.variable
end

#accept(visitor) ⇒ Object



9212
9213
9214
# File 'lib/syntax_tree/node.rb', line 9212

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

#child_nodesObject Also known as: deconstruct



9216
9217
9218
# File 'lib/syntax_tree/node.rb', line 9216

def child_nodes
  [*exceptions, variable]
end

#copy(exceptions: nil, variable: nil, location: nil) ⇒ Object



9220
9221
9222
9223
9224
9225
9226
9227
9228
9229
9230
# File 'lib/syntax_tree/node.rb', line 9220

def copy(exceptions: nil, variable: nil, location: nil)
  node =
    RescueEx.new(
      exceptions: exceptions || self.exceptions,
      variable: variable || self.variable,
      location: location || self.location
    )

  node.comments.concat(comments.map(&:copy))
  node
end

#deconstruct_keys(_keys) ⇒ Object



9234
9235
9236
9237
9238
9239
9240
9241
# File 'lib/syntax_tree/node.rb', line 9234

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

#format(q) ⇒ Object



9243
9244
9245
9246
9247
9248
9249
9250
9251
9252
9253
9254
9255
# File 'lib/syntax_tree/node.rb', line 9243

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

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