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



3008
3009
3010
3011
3012
3013
# File 'lib/yarp/node.rb', line 3008

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



3002
3003
3004
# File 'lib/yarp/node.rb', line 3002

def operator_loc
  @operator_loc
end

#targetObject (readonly)

attr_reader target: ConstantPathNode



2999
3000
3001
# File 'lib/yarp/node.rb', line 2999

def target
  @target
end

#valueObject (readonly)

attr_reader value: Node



3005
3006
3007
# File 'lib/yarp/node.rb', line 3005

def value
  @value
end

Instance Method Details

#accept(visitor) ⇒ Object

def accept: (visitor: Visitor) -> void



3016
3017
3018
# File 'lib/yarp/node.rb', line 3016

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

#child_nodesObject Also known as: deconstruct

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



3021
3022
3023
# File 'lib/yarp/node.rb', line 3021

def child_nodes
  [target, value]
end

#comment_targetsObject

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



3026
3027
3028
# File 'lib/yarp/node.rb', line 3026

def comment_targets
  [target, operator_loc, value]
end

#copy(**params) ⇒ Object

def copy: (**params) -> ConstantPathOrWriteNode



3031
3032
3033
3034
3035
3036
3037
3038
# File 'lib/yarp/node.rb', line 3031

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]



3044
3045
3046
# File 'lib/yarp/node.rb', line 3044

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

#inspect(inspector = NodeInspector.new) ⇒ Object



3053
3054
3055
3056
3057
3058
3059
3060
3061
# File 'lib/yarp/node.rb', line 3053

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



3049
3050
3051
# File 'lib/yarp/node.rb', line 3049

def operator
  operator_loc.slice
end