Class: YARP::ConstantPathAndWriteNode

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) ⇒ ConstantPathAndWriteNode

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



2790
2791
2792
2793
2794
2795
# File 'lib/yarp/node.rb', line 2790

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



2784
2785
2786
# File 'lib/yarp/node.rb', line 2784

def operator_loc
  @operator_loc
end

#targetObject (readonly)

attr_reader target: ConstantPathNode



2781
2782
2783
# File 'lib/yarp/node.rb', line 2781

def target
  @target
end

#valueObject (readonly)

attr_reader value: Node



2787
2788
2789
# File 'lib/yarp/node.rb', line 2787

def value
  @value
end

Instance Method Details

#accept(visitor) ⇒ Object

def accept: (visitor: Visitor) -> void



2798
2799
2800
# File 'lib/yarp/node.rb', line 2798

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

#child_nodesObject Also known as: deconstruct

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



2803
2804
2805
# File 'lib/yarp/node.rb', line 2803

def child_nodes
  [target, value]
end

#comment_targetsObject

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



2808
2809
2810
# File 'lib/yarp/node.rb', line 2808

def comment_targets
  [target, operator_loc, value]
end

#copy(**params) ⇒ Object

def copy: (**params) -> ConstantPathAndWriteNode



2813
2814
2815
2816
2817
2818
2819
2820
# File 'lib/yarp/node.rb', line 2813

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



2826
2827
2828
# File 'lib/yarp/node.rb', line 2826

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

#inspect(inspector = NodeInspector.new) ⇒ Object



2835
2836
2837
2838
2839
2840
2841
2842
2843
# File 'lib/yarp/node.rb', line 2835

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



2831
2832
2833
# File 'lib/yarp/node.rb', line 2831

def operator
  operator_loc.slice
end