Class: Prism::CapturePatternNode

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

Overview

Represents assigning to a local variable in pattern matching.

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source, node_id, location, flags, value, target, operator_loc) ⇒ CapturePatternNode

Initialize a new CapturePatternNode node.



2911
2912
2913
2914
2915
2916
2917
2918
2919
# File 'lib/prism/node.rb', line 2911

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

Instance Attribute Details

#targetObject (readonly)

attr_reader target: LocalVariableTargetNode



2958
2959
2960
# File 'lib/prism/node.rb', line 2958

def target
  @target
end

#valueObject (readonly)

attr_reader value: Prism::node



2955
2956
2957
# File 'lib/prism/node.rb', line 2955

def value
  @value
end

Class Method Details

.typeObject

Return a symbol representation of this node type. See ‘Node::type`.



2983
2984
2985
# File 'lib/prism/node.rb', line 2983

def self.type
  :capture_pattern_node
end

Instance Method Details

#===(other) ⇒ Object

Implements case-equality for the node. This is effectively == but without comparing the value of locations. Locations are checked only for presence.



2989
2990
2991
2992
2993
2994
# File 'lib/prism/node.rb', line 2989

def ===(other)
  other.is_a?(CapturePatternNode) &&
    (value === other.value) &&
    (target === other.target) &&
    (operator_loc.nil? == other.operator_loc.nil?)
end

#accept(visitor) ⇒ Object

def accept: (Visitor visitor) -> void



2922
2923
2924
# File 'lib/prism/node.rb', line 2922

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

#child_nodesObject Also known as: deconstruct

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



2927
2928
2929
# File 'lib/prism/node.rb', line 2927

def child_nodes
  [value, target]
end

#comment_targetsObject

def comment_targets: () -> Array[Node | Location]



2937
2938
2939
# File 'lib/prism/node.rb', line 2937

def comment_targets
  [value, target, operator_loc] #: Array[Prism::node | Location]
end

#compact_child_nodesObject

def compact_child_nodes: () -> Array



2932
2933
2934
# File 'lib/prism/node.rb', line 2932

def compact_child_nodes
  [value, target]
end

#copy(node_id: self.node_id, location: self.location, flags: self.flags, value: self.value, target: self.target, operator_loc: self.operator_loc) ⇒ Object

def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?value: Prism::node, ?target: LocalVariableTargetNode, ?operator_loc: Location) -> CapturePatternNode



2942
2943
2944
# File 'lib/prism/node.rb', line 2942

def copy(node_id: self.node_id, location: self.location, flags: self.flags, value: self.value, target: self.target, operator_loc: self.operator_loc)
  CapturePatternNode.new(source, node_id, location, flags, value, target, operator_loc)
end

#deconstruct_keys(keys) ⇒ Object

def deconstruct_keys: (Array keys) -> { node_id: Integer, location: Location, value: Prism::node, target: LocalVariableTargetNode, operator_loc: Location }



2950
2951
2952
# File 'lib/prism/node.rb', line 2950

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

#inspectObject

def inspect -> String



2973
2974
2975
# File 'lib/prism/node.rb', line 2973

def inspect
  InspectVisitor.compose(self)
end

#operatorObject

def operator: () -> String



2968
2969
2970
# File 'lib/prism/node.rb', line 2968

def operator
  operator_loc.slice
end

#operator_locObject

attr_reader operator_loc: Location



2961
2962
2963
2964
2965
# File 'lib/prism/node.rb', line 2961

def operator_loc
  location = @operator_loc
  return location if location.is_a?(Location)
  @operator_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
end

#typeObject

Return a symbol representation of this node type. See ‘Node#type`.



2978
2979
2980
# File 'lib/prism/node.rb', line 2978

def type
  :capture_pattern_node
end