Class: YARP::ConstantPathWriteNode

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

Overview

Represents writing to a constant path.

::Foo = 1
^^^^^^^^^

Foo::Bar = 1
^^^^^^^^^^^^

::Foo::Bar = 1
^^^^^^^^^^^^^^

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

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



2217
2218
2219
2220
2221
2222
# File 'lib/yarp/node.rb', line 2217

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



2211
2212
2213
# File 'lib/yarp/node.rb', line 2211

def operator_loc
  @operator_loc
end

#targetObject (readonly)

attr_reader target: ConstantPathNode



2208
2209
2210
# File 'lib/yarp/node.rb', line 2208

def target
  @target
end

#valueObject (readonly)

attr_reader value: Node



2214
2215
2216
# File 'lib/yarp/node.rb', line 2214

def value
  @value
end

Instance Method Details

#accept(visitor) ⇒ Object

def accept: (visitor: Visitor) -> void



2225
2226
2227
# File 'lib/yarp/node.rb', line 2225

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

#child_nodesObject Also known as: deconstruct

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



2230
2231
2232
# File 'lib/yarp/node.rb', line 2230

def child_nodes
  [target, value]
end

#copy(**params) ⇒ Object

def copy: (**params) -> ConstantPathWriteNode



2235
2236
2237
2238
2239
2240
2241
2242
# File 'lib/yarp/node.rb', line 2235

def copy(**params)
  ConstantPathWriteNode.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]



2248
2249
2250
# File 'lib/yarp/node.rb', line 2248

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

#operatorObject

def operator: () -> String



2253
2254
2255
# File 'lib/yarp/node.rb', line 2253

def operator
  operator_loc.slice
end