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



1018
1019
1020
1021
1022
1023
# File 'lib/yarp/node.rb', line 1018

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



1015
1016
1017
# File 'lib/yarp/node.rb', line 1015

def operator_loc
  @operator_loc
end

#targetObject (readonly)

attr_reader target: Node



1012
1013
1014
# File 'lib/yarp/node.rb', line 1012

def target
  @target
end

#valueObject (readonly)

attr_reader value: Node



1009
1010
1011
# File 'lib/yarp/node.rb', line 1009

def value
  @value
end

Instance Method Details

#accept(visitor) ⇒ Object

def accept: (visitor: Visitor) -> void



1026
1027
1028
# File 'lib/yarp/node.rb', line 1026

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

#child_nodesObject Also known as: deconstruct

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



1032
1033
1034
# File 'lib/yarp/node.rb', line 1032

def child_nodes
  [value, target]
end

#deconstruct_keys(keys) ⇒ Object

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



1040
1041
1042
# File 'lib/yarp/node.rb', line 1040

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

#operatorObject

def operator: () -> String



1045
1046
1047
# File 'lib/yarp/node.rb', line 1045

def operator
  operator_loc.slice
end