123456789_123456789_123456789_123456789_123456789_

Class: Prism::CapturePatternNode

Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
self, PrismNode
Instance Chain:
self, PrismNode
Inherits: PrismNode
  • ::Object
Defined in: lib/prism/node.rb,
ext/prism/api_node.c

Overview

Represents assigning to a local variable in pattern matching.

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

Class Method Summary

Instance Attribute Summary

  • #target readonly

    attr_reader target: Prism.node

  • #value readonly

    attr_reader value: Prism.node

Instance Method Summary

Constructor Details

.new(source, node_id, location, flags, value, target, operator_loc) ⇒ CapturePatternNode

Initialize a new CapturePatternNode node.

[ GitHub ]

  
# File 'lib/prism/node.rb', line 2819

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

Class Method Details

.type

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

[ GitHub ]

  
# File 'lib/prism/node.rb', line 2889

def self.type
  :capture_pattern_node
end

Instance Attribute Details

#target (readonly)

attr_reader target: Prism.node

[ GitHub ]

  
# File 'lib/prism/node.rb', line 2865

attr_reader :target

#value (readonly)

attr_reader value: Prism.node

[ GitHub ]

  
# File 'lib/prism/node.rb', line 2863

attr_reader :value

Instance Method Details

#===(other)

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

[ GitHub ]

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

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

#accept(visitor)

def accept: (Visitor visitor) -> void

[ GitHub ]

  
# File 'lib/prism/node.rb', line 2830

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

#child_nodes Also known as: #deconstruct

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

[ GitHub ]

  
# File 'lib/prism/node.rb', line 2835

def child_nodes
  [value, target]
end

#comment_targets

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

[ GitHub ]

  
# File 'lib/prism/node.rb', line 2845

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

#compact_child_nodes

def compact_child_nodes: () -> Array

[ GitHub ]

  
# File 'lib/prism/node.rb', line 2840

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)

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

[ GitHub ]

  
# File 'lib/prism/node.rb', line 2850

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

Alias for #child_nodes.

[ GitHub ]

  
# File 'lib/prism/node.rb', line 2855

alias deconstruct child_nodes

#deconstruct_keys(keys)

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

[ GitHub ]

  
# File 'lib/prism/node.rb', line 2858

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

#inspect

def inspect -> String

[ GitHub ]

  
# File 'lib/prism/node.rb', line 2879

def inspect
  InspectVisitor.compose(self)
end

#operator

def operator: () -> String

[ GitHub ]

  
# File 'lib/prism/node.rb', line 2874

def operator
  operator_loc.slice
end

#operator_loc

attr_reader operator_loc: Location

[ GitHub ]

  
# File 'lib/prism/node.rb', line 2867

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

#type

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

[ GitHub ]

  
# File 'lib/prism/node.rb', line 2884

def type
  :capture_pattern_node
end