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.



10106
10107
10108
10109
10110
10111
# File 'lib/syntax_tree.rb', line 10106

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



10104
10105
10106
# File 'lib/syntax_tree.rb', line 10104

def comments
  @comments
end

#exceptionsObject (readonly)

untyped

the list of exceptions being rescued



10094
10095
10096
# File 'lib/syntax_tree.rb', line 10094

def exceptions
  @exceptions
end

#locationObject (readonly)

Location

the location of this node



10101
10102
10103
# File 'lib/syntax_tree.rb', line 10101

def location
  @location
end

#variableObject (readonly)

nil | Field | VarField

the expression being used to capture the raised

exception



10098
10099
10100
# File 'lib/syntax_tree.rb', line 10098

def variable
  @variable
end

Instance Method Details

#child_nodesObject



10113
10114
10115
# File 'lib/syntax_tree.rb', line 10113

def child_nodes
  [*exceptions, variable]
end

#format(q) ⇒ Object



10117
10118
10119
10120
10121
10122
10123
10124
10125
10126
10127
10128
10129
# File 'lib/syntax_tree.rb', line 10117

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



10131
10132
10133
10134
10135
10136
10137
10138
10139
10140
10141
10142
10143
# File 'lib/syntax_tree.rb', line 10131

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



10145
10146
10147
10148
10149
10150
10151
10152
10153
# File 'lib/syntax_tree.rb', line 10145

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