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



3160
3161
3162
3163
3164
3165
# File 'lib/yarp/node.rb', line 3160

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



3154
3155
3156
# File 'lib/yarp/node.rb', line 3154

def operator_loc
  @operator_loc
end

#targetObject (readonly)

attr_reader target: ConstantPathNode



3151
3152
3153
# File 'lib/yarp/node.rb', line 3151

def target
  @target
end

#valueObject (readonly)

attr_reader value: Node



3157
3158
3159
# File 'lib/yarp/node.rb', line 3157

def value
  @value
end

Instance Method Details

#accept(visitor) ⇒ Object

def accept: (visitor: Visitor) -> void



3168
3169
3170
# File 'lib/yarp/node.rb', line 3168

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

#child_nodesObject Also known as: deconstruct

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



3173
3174
3175
# File 'lib/yarp/node.rb', line 3173

def child_nodes
  [target, value]
end

#comment_targetsObject

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



3178
3179
3180
# File 'lib/yarp/node.rb', line 3178

def comment_targets
  [target, operator_loc, value]
end

#copy(**params) ⇒ Object

def copy: (**params) -> ConstantPathWriteNode



3183
3184
3185
3186
3187
3188
3189
3190
# File 'lib/yarp/node.rb', line 3183

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]



3196
3197
3198
# File 'lib/yarp/node.rb', line 3196

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

#inspect(inspector = NodeInspector.new) ⇒ Object



3205
3206
3207
3208
3209
3210
3211
3212
3213
# File 'lib/yarp/node.rb', line 3205

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

#operatorObject

def operator: () -> String



3201
3202
3203
# File 'lib/yarp/node.rb', line 3201

def operator
  operator_loc.slice
end