Class: YARP::CapturePatternNode

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

Overview

Represents assigning to a local variable in pattern matching.

foo => [bar => baz]
       ^^^^^^^^^^^^

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value, target, operator_loc, location) ⇒ CapturePatternNode

def initialize: (value: Node, target: Node, operator_loc: Location, location: Location) -> void



1202
1203
1204
1205
1206
1207
# File 'lib/yarp/node.rb', line 1202

def initialize(value, target, operator_loc, location)
  @value = value
  @target = target
  @operator_loc = operator_loc
  @location = location
end

Instance Attribute Details

#operator_locObject (readonly)

attr_reader operator_loc: Location



1199
1200
1201
# File 'lib/yarp/node.rb', line 1199

def operator_loc
  @operator_loc
end

#targetObject (readonly)

attr_reader target: Node



1196
1197
1198
# File 'lib/yarp/node.rb', line 1196

def target
  @target
end

#valueObject (readonly)

attr_reader value: Node



1193
1194
1195
# File 'lib/yarp/node.rb', line 1193

def value
  @value
end

Instance Method Details

#accept(visitor) ⇒ Object

def accept: (visitor: Visitor) -> void



1210
1211
1212
# File 'lib/yarp/node.rb', line 1210

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

#child_nodesObject Also known as: deconstruct

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



1215
1216
1217
# File 'lib/yarp/node.rb', line 1215

def child_nodes
  [value, target]
end

#copy(**params) ⇒ Object

def copy: (**params) -> CapturePatternNode



1220
1221
1222
1223
1224
1225
1226
1227
# File 'lib/yarp/node.rb', line 1220

def copy(**params)
  CapturePatternNode.new(
    params.fetch(:value) { value },
    params.fetch(:target) { target },
    params.fetch(:operator_loc) { operator_loc },
    params.fetch(:location) { location },
  )
end

#deconstruct_keys(keys) ⇒ Object

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



1233
1234
1235
# File 'lib/yarp/node.rb', line 1233

def deconstruct_keys(keys)
  { value: value, target: target, operator_loc: operator_loc, location: location }
end

#operatorObject

def operator: () -> String



1238
1239
1240
# File 'lib/yarp/node.rb', line 1238

def operator
  operator_loc.slice
end