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



5320
5321
5322
5323
5324
5325
5326
5327
5328
# File 'lib/yarp/node.rb', line 5320

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?



5317
5318
5319
# File 'lib/yarp/node.rb', line 5317

def consequent
  @consequent
end

#exceptionsObject (readonly)

attr_reader exceptions: Array



5305
5306
5307
# File 'lib/yarp/node.rb', line 5305

def exceptions
  @exceptions
end

#keyword_locObject (readonly)

attr_reader keyword_loc: Location



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

def keyword_loc
  @keyword_loc
end

#operator_locObject (readonly)

attr_reader operator_loc: Location?



5308
5309
5310
# File 'lib/yarp/node.rb', line 5308

def operator_loc
  @operator_loc
end

#referenceObject (readonly)

attr_reader reference: Node?



5311
5312
5313
# File 'lib/yarp/node.rb', line 5311

def reference
  @reference
end

#statementsObject (readonly)

attr_reader statements: Node?



5314
5315
5316
# File 'lib/yarp/node.rb', line 5314

def statements
  @statements
end

Instance Method Details

#accept(visitor) ⇒ Object

def accept: (visitor: Visitor) -> void



5331
5332
5333
# File 'lib/yarp/node.rb', line 5331

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

#child_nodesObject Also known as: deconstruct

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



5336
5337
5338
# File 'lib/yarp/node.rb', line 5336

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]



5344
5345
5346
# File 'lib/yarp/node.rb', line 5344

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



5349
5350
5351
# File 'lib/yarp/node.rb', line 5349

def keyword
  keyword_loc.slice
end

#operatorObject

def operator: () -> String?



5354
5355
5356
# File 'lib/yarp/node.rb', line 5354

def operator
  operator_loc&.slice
end