Class: YARP::PinnedVariableNode

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

Overview

Represents the use of the ‘^` operator for pinning a variable in a pattern matching expression.

foo in ^bar
       ^^^^

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(variable, operator_loc, location) ⇒ PinnedVariableNode

def initialize: (variable: Node, operator_loc: Location, location: Location) -> void



8017
8018
8019
8020
8021
# File 'lib/yarp/node.rb', line 8017

def initialize(variable, operator_loc, location)
  @variable = variable
  @operator_loc = operator_loc
  @location = location
end

Instance Attribute Details

#operator_locObject (readonly)

attr_reader operator_loc: Location



8014
8015
8016
# File 'lib/yarp/node.rb', line 8014

def operator_loc
  @operator_loc
end

#variableObject (readonly)

attr_reader variable: Node



8011
8012
8013
# File 'lib/yarp/node.rb', line 8011

def variable
  @variable
end

Instance Method Details

#accept(visitor) ⇒ Object

def accept: (visitor: Visitor) -> void



8024
8025
8026
# File 'lib/yarp/node.rb', line 8024

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

#child_nodesObject Also known as: deconstruct

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



8029
8030
8031
# File 'lib/yarp/node.rb', line 8029

def child_nodes
  [variable]
end

#comment_targetsObject

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



8034
8035
8036
# File 'lib/yarp/node.rb', line 8034

def comment_targets
  [variable, operator_loc]
end

#copy(**params) ⇒ Object

def copy: (**params) -> PinnedVariableNode



8039
8040
8041
8042
8043
8044
8045
# File 'lib/yarp/node.rb', line 8039

def copy(**params)
  PinnedVariableNode.new(
    params.fetch(:variable) { variable },
    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]



8051
8052
8053
# File 'lib/yarp/node.rb', line 8051

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

#inspect(inspector = NodeInspector.new) ⇒ Object



8060
8061
8062
8063
8064
8065
8066
# File 'lib/yarp/node.rb', line 8060

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

#operatorObject

def operator: () -> String



8056
8057
8058
# File 'lib/yarp/node.rb', line 8056

def operator
  operator_loc.slice
end