Class: YARP::ConstantPathOperatorWriteNode

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

Overview

Represents assigning to a constant path using an operator that isn’t ‘=`.

Parent::Child += value
^^^^^^^^^^^^^^^^^^^^^^

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(target, operator_loc, value, operator, location) ⇒ ConstantPathOperatorWriteNode

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



2939
2940
2941
2942
2943
2944
2945
# File 'lib/yarp/node.rb', line 2939

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

Instance Attribute Details

#operatorObject (readonly)

attr_reader operator: Symbol



2936
2937
2938
# File 'lib/yarp/node.rb', line 2936

def operator
  @operator
end

#operator_locObject (readonly)

attr_reader operator_loc: Location



2930
2931
2932
# File 'lib/yarp/node.rb', line 2930

def operator_loc
  @operator_loc
end

#targetObject (readonly)

attr_reader target: ConstantPathNode



2927
2928
2929
# File 'lib/yarp/node.rb', line 2927

def target
  @target
end

#valueObject (readonly)

attr_reader value: Node



2933
2934
2935
# File 'lib/yarp/node.rb', line 2933

def value
  @value
end

Instance Method Details

#accept(visitor) ⇒ Object

def accept: (visitor: Visitor) -> void



2948
2949
2950
# File 'lib/yarp/node.rb', line 2948

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

#child_nodesObject Also known as: deconstruct

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



2953
2954
2955
# File 'lib/yarp/node.rb', line 2953

def child_nodes
  [target, value]
end

#comment_targetsObject

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



2958
2959
2960
# File 'lib/yarp/node.rb', line 2958

def comment_targets
  [target, operator_loc, value]
end

#copy(**params) ⇒ Object

def copy: (**params) -> ConstantPathOperatorWriteNode



2963
2964
2965
2966
2967
2968
2969
2970
2971
# File 'lib/yarp/node.rb', line 2963

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

#deconstruct_keys(keys) ⇒ Object

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



2977
2978
2979
# File 'lib/yarp/node.rb', line 2977

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

#inspect(inspector = NodeInspector.new) ⇒ Object



2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
# File 'lib/yarp/node.rb', line 2981

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 << "└── operator: #{operator.inspect}\n"
  inspector.to_str
end