Class: YARP::ConstantPathOrWriteNode

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

Overview

Represents the use of the ‘||=` operator for assignment to a constant path.

Parent::Child ||= value
^^^^^^^^^^^^^^^^^^^^^^^

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(target, operator_loc, value, location) ⇒ ConstantPathOrWriteNode

def initialize: (target: ConstantPathNode, operator_loc: Location, value: Node, location: Location) -> void



2099
2100
2101
2102
2103
2104
# File 'lib/yarp/node.rb', line 2099

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

Instance Attribute Details

#operator_locObject (readonly)

attr_reader operator_loc: Location



2093
2094
2095
# File 'lib/yarp/node.rb', line 2093

def operator_loc
  @operator_loc
end

#targetObject (readonly)

attr_reader target: ConstantPathNode



2090
2091
2092
# File 'lib/yarp/node.rb', line 2090

def target
  @target
end

#valueObject (readonly)

attr_reader value: Node



2096
2097
2098
# File 'lib/yarp/node.rb', line 2096

def value
  @value
end

Instance Method Details

#accept(visitor) ⇒ Object

def accept: (visitor: Visitor) -> void



2107
2108
2109
# File 'lib/yarp/node.rb', line 2107

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

#child_nodesObject Also known as: deconstruct

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



2112
2113
2114
# File 'lib/yarp/node.rb', line 2112

def child_nodes
  [target, value]
end

#copy(**params) ⇒ Object

def copy: (**params) -> ConstantPathOrWriteNode



2117
2118
2119
2120
2121
2122
2123
2124
# File 'lib/yarp/node.rb', line 2117

def copy(**params)
  ConstantPathOrWriteNode.new(
    params.fetch(:target) { target },
    params.fetch(:operator_loc) { operator_loc },
    params.fetch(:value) { value },
    params.fetch(:location) { location },
  )
end

#deconstruct_keys(keys) ⇒ Object

def deconstruct_keys: (keys: Array) -> Hash[Symbol, nil | Node | Array | String | Token | Array | Location]



2130
2131
2132
# File 'lib/yarp/node.rb', line 2130

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

#operatorObject

def operator: () -> String



2135
2136
2137
# File 'lib/yarp/node.rb', line 2135

def operator
  operator_loc.slice
end