Class: SyntaxTree::RescueEx

Inherits:
Object
  • Object
show all
Defined in:
lib/syntax_tree.rb

Overview

RescueEx represents the list of exceptions being rescued in a rescue clause.

begin
rescue Exception => exception
end

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of RescueEx.



10182
10183
10184
10185
10186
10187
# File 'lib/syntax_tree.rb', line 10182

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



10180
10181
10182
# File 'lib/syntax_tree.rb', line 10180

def comments
  @comments
end

#exceptionsObject (readonly)

untyped

the list of exceptions being rescued



10170
10171
10172
# File 'lib/syntax_tree.rb', line 10170

def exceptions
  @exceptions
end

#locationObject (readonly)

Location

the location of this node



10177
10178
10179
# File 'lib/syntax_tree.rb', line 10177

def location
  @location
end

#variableObject (readonly)

nil | Field | VarField

the expression being used to capture the raised

exception



10174
10175
10176
# File 'lib/syntax_tree.rb', line 10174

def variable
  @variable
end

Instance Method Details

#child_nodesObject



10189
10190
10191
# File 'lib/syntax_tree.rb', line 10189

def child_nodes
  [*exceptions, variable]
end

#format(q) ⇒ Object



10193
10194
10195
10196
10197
10198
10199
10200
10201
10202
10203
10204
10205
# File 'lib/syntax_tree.rb', line 10193

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

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

#pretty_print(q) ⇒ Object



10207
10208
10209
10210
10211
10212
10213
10214
10215
10216
10217
10218
10219
# File 'lib/syntax_tree.rb', line 10207

def pretty_print(q)
  q.group(2, "(", ")") do
    q.text("rescue_ex")

    q.breakable
    q.pp(exceptions)

    q.breakable
    q.pp(variable)

    q.pp(Comment::List.new(comments))
  end
end

#to_json(*opts) ⇒ Object



10221
10222
10223
10224
10225
10226
10227
10228
10229
# File 'lib/syntax_tree.rb', line 10221

def to_json(*opts)
  {
    type: :rescue_ex,
    extns: exceptions,
    var: variable,
    loc: location,
    cmts: comments
  }.to_json(*opts)
end