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



1863
1864
1865
1866
1867
1868
# File 'lib/yarp/node.rb', line 1863

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



1860
1861
1862
# File 'lib/yarp/node.rb', line 1860

def operator_loc
  @operator_loc
end

#targetObject (readonly)

attr_reader target: Node



1857
1858
1859
# File 'lib/yarp/node.rb', line 1857

def target
  @target
end

#valueObject (readonly)

attr_reader value: Node



1854
1855
1856
# File 'lib/yarp/node.rb', line 1854

def value
  @value
end

Instance Method Details

#accept(visitor) ⇒ Object

def accept: (visitor: Visitor) -> void



1871
1872
1873
# File 'lib/yarp/node.rb', line 1871

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

#child_nodesObject Also known as: deconstruct

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



1876
1877
1878
# File 'lib/yarp/node.rb', line 1876

def child_nodes
  [value, target]
end

#comment_targetsObject

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



1881
1882
1883
# File 'lib/yarp/node.rb', line 1881

def comment_targets
  [value, target, operator_loc]
end

#copy(**params) ⇒ Object

def copy: (**params) -> CapturePatternNode



1886
1887
1888
1889
1890
1891
1892
1893
# File 'lib/yarp/node.rb', line 1886

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]



1899
1900
1901
# File 'lib/yarp/node.rb', line 1899

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

#inspect(inspector = NodeInspector.new) ⇒ Object



1908
1909
1910
1911
1912
1913
1914
1915
1916
# File 'lib/yarp/node.rb', line 1908

def inspect(inspector = NodeInspector.new)
  inspector << inspector.header(self)
  inspector << "├── value:\n"
  inspector << inspector.child_node(value, "│   ")
  inspector << "├── target:\n"
  inspector << inspector.child_node(target, "│   ")
  inspector << "└── operator_loc: #{inspector.location(operator_loc)}\n"
  inspector.to_str
end

#operatorObject

def operator: () -> String



1904
1905
1906
# File 'lib/yarp/node.rb', line 1904

def operator
  operator_loc.slice
end