Class: YARP::ClassVariableAndWriteNode

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 class variable.

@@target &&= value
^^^^^^^^^^^^^^^^

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, name_loc, operator_loc, value, location) ⇒ ClassVariableAndWriteNode

def initialize: (name: Symbol, name_loc: Location, operator_loc: Location, value: Node, location: Location) -> void



1425
1426
1427
1428
1429
1430
1431
# File 'lib/yarp/node.rb', line 1425

def initialize(name, name_loc, operator_loc, value, location)
  @name = name
  @name_loc = name_loc
  @operator_loc = operator_loc
  @value = value
  @location = location
end

Instance Attribute Details

#nameObject (readonly)

attr_reader name: Symbol



1413
1414
1415
# File 'lib/yarp/node.rb', line 1413

def name
  @name
end

#name_locObject (readonly)

attr_reader name_loc: Location



1416
1417
1418
# File 'lib/yarp/node.rb', line 1416

def name_loc
  @name_loc
end

#operator_locObject (readonly)

attr_reader operator_loc: Location



1419
1420
1421
# File 'lib/yarp/node.rb', line 1419

def operator_loc
  @operator_loc
end

#valueObject (readonly)

attr_reader value: Node



1422
1423
1424
# File 'lib/yarp/node.rb', line 1422

def value
  @value
end

Instance Method Details

#accept(visitor) ⇒ Object

def accept: (visitor: Visitor) -> void



1434
1435
1436
# File 'lib/yarp/node.rb', line 1434

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

#child_nodesObject Also known as: deconstruct

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



1439
1440
1441
# File 'lib/yarp/node.rb', line 1439

def child_nodes
  [value]
end

#copy(**params) ⇒ Object

def copy: (**params) -> ClassVariableAndWriteNode



1444
1445
1446
1447
1448
1449
1450
1451
1452
# File 'lib/yarp/node.rb', line 1444

def copy(**params)
  ClassVariableAndWriteNode.new(
    params.fetch(:name) { name },
    params.fetch(:name_loc) { name_loc },
    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]



1458
1459
1460
# File 'lib/yarp/node.rb', line 1458

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

#operatorObject

def operator: () -> String



1463
1464
1465
# File 'lib/yarp/node.rb', line 1463

def operator
  operator_loc.slice
end