Class: YARP::RescueNode

Inherits:
YARPNode
  • Object
show all
Defined in:
lib/yarp/node.rb,
ext/yarp/api_node.c

Overview

Represents a rescue statement.

begin
rescue Foo, *splat, Bar => ex
^^^^^^
  foo
end

‘Foo, *splat, Bar` are in the `exceptions` field. `ex` is in the `exception` field.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(keyword_loc, exceptions, operator_loc, reference, statements, consequent, location) ⇒ RescueNode

def initialize: (keyword_loc: Location, exceptions: Array, operator_loc: Location?, reference: Node?, statements: Node?, consequent: Node?, location: Location) -> void



5266
5267
5268
5269
5270
5271
5272
5273
5274
# File 'lib/yarp/node.rb', line 5266

def initialize(keyword_loc, exceptions, operator_loc, reference, statements, consequent, location)
  @keyword_loc = keyword_loc
  @exceptions = exceptions
  @operator_loc = operator_loc
  @reference = reference
  @statements = statements
  @consequent = consequent
  @location = location
end

Instance Attribute Details

#consequentObject (readonly)

attr_reader consequent: Node?



5263
5264
5265
# File 'lib/yarp/node.rb', line 5263

def consequent
  @consequent
end

#exceptionsObject (readonly)

attr_reader exceptions: Array



5251
5252
5253
# File 'lib/yarp/node.rb', line 5251

def exceptions
  @exceptions
end

#keyword_locObject (readonly)

attr_reader keyword_loc: Location



5248
5249
5250
# File 'lib/yarp/node.rb', line 5248

def keyword_loc
  @keyword_loc
end

#operator_locObject (readonly)

attr_reader operator_loc: Location?



5254
5255
5256
# File 'lib/yarp/node.rb', line 5254

def operator_loc
  @operator_loc
end

#referenceObject (readonly)

attr_reader reference: Node?



5257
5258
5259
# File 'lib/yarp/node.rb', line 5257

def reference
  @reference
end

#statementsObject (readonly)

attr_reader statements: Node?



5260
5261
5262
# File 'lib/yarp/node.rb', line 5260

def statements
  @statements
end

Instance Method Details

#accept(visitor) ⇒ Object

def accept: (visitor: Visitor) -> void



5277
5278
5279
# File 'lib/yarp/node.rb', line 5277

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

#child_nodesObject Also known as: deconstruct

def child_nodes: () -> Array[nil | Node]



5283
5284
5285
# File 'lib/yarp/node.rb', line 5283

def child_nodes
  [*exceptions, reference, statements, consequent]
end

#deconstruct_keys(keys) ⇒ Object

def deconstruct_keys: (keys: Array) -> Hash[Symbol, nil | Node | Array | String | Token | Array | Location]



5291
5292
5293
# File 'lib/yarp/node.rb', line 5291

def deconstruct_keys(keys)
  { keyword_loc: keyword_loc, exceptions: exceptions, operator_loc: operator_loc, reference: reference, statements: statements, consequent: consequent, location: location }
end

#keywordObject

def keyword: () -> String



5296
5297
5298
# File 'lib/yarp/node.rb', line 5296

def keyword
  keyword_loc.slice
end

#operatorObject

def operator: () -> String?



5301
5302
5303
# File 'lib/yarp/node.rb', line 5301

def operator
  operator_loc&.slice
end