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.



2874
2875
2876
2877
2878
2879
2880
2881
2882
# File 'lib/prism/node.rb', line 2874

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: Prism::node



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

def target
  @target
end

#valueObject (readonly)

attr_reader value: Prism::node



2918
2919
2920
# File 'lib/prism/node.rb', line 2918

def value
  @value
end

Class Method Details

.typeObject

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



2946
2947
2948
# File 'lib/prism/node.rb', line 2946

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.



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

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



2885
2886
2887
# File 'lib/prism/node.rb', line 2885

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

#child_nodesObject Also known as: deconstruct

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



2890
2891
2892
# File 'lib/prism/node.rb', line 2890

def child_nodes
  [value, target]
end

#comment_targetsObject

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



2900
2901
2902
# File 'lib/prism/node.rb', line 2900

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

#compact_child_nodesObject

def compact_child_nodes: () -> Array



2895
2896
2897
# File 'lib/prism/node.rb', line 2895

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: Prism::node, ?operator_loc: Location) -> CapturePatternNode



2905
2906
2907
# File 'lib/prism/node.rb', line 2905

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: Prism::node, operator_loc: Location }



2913
2914
2915
# File 'lib/prism/node.rb', line 2913

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

#inspectObject

def inspect -> String



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

def inspect
  InspectVisitor.compose(self)
end

#operatorObject

def operator: () -> String



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

def operator
  operator_loc.slice
end

#operator_locObject

attr_reader operator_loc: Location



2924
2925
2926
2927
2928
# File 'lib/prism/node.rb', line 2924

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`.



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

def type
  :capture_pattern_node
end