Class: YARP::CallOperatorOrWriteNode

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

Overview

Represents the use of the ‘||=` operator on a call.

foo.bar ||= value
^^^^^^^^^^^^^^^^^

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

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



1090
1091
1092
1093
1094
1095
# File 'lib/yarp/node.rb', line 1090

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

Instance Attribute Details

#operator_locObject (readonly)

attr_reader operator_loc: Location



1087
1088
1089
# File 'lib/yarp/node.rb', line 1087

def operator_loc
  @operator_loc
end

#targetObject (readonly)

attr_reader target: CallNode



1081
1082
1083
# File 'lib/yarp/node.rb', line 1081

def target
  @target
end

#valueObject (readonly)

attr_reader value: Node



1084
1085
1086
# File 'lib/yarp/node.rb', line 1084

def value
  @value
end

Instance Method Details

#accept(visitor) ⇒ Object

def accept: (visitor: Visitor) -> void



1098
1099
1100
# File 'lib/yarp/node.rb', line 1098

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

#child_nodesObject Also known as: deconstruct

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



1103
1104
1105
# File 'lib/yarp/node.rb', line 1103

def child_nodes
  [target, value]
end

#copy(**params) ⇒ Object

def copy: (**params) -> CallOperatorOrWriteNode



1108
1109
1110
1111
1112
1113
1114
1115
# File 'lib/yarp/node.rb', line 1108

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

#deconstruct_keys(keys) ⇒ Object

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



1121
1122
1123
# File 'lib/yarp/node.rb', line 1121

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

#operatorObject

def operator: () -> String



1126
1127
1128
# File 'lib/yarp/node.rb', line 1126

def operator
  operator_loc.slice
end