Class: YARP::ClassVariableWriteNode

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

Overview

Represents writing to a class variable.

@@foo = 1
^^^^^^^^^

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

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



2488
2489
2490
2491
2492
2493
2494
# File 'lib/yarp/node.rb', line 2488

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

Instance Attribute Details

#nameObject (readonly)

attr_reader name: Symbol



2476
2477
2478
# File 'lib/yarp/node.rb', line 2476

def name
  @name
end

#name_locObject (readonly)

attr_reader name_loc: Location



2479
2480
2481
# File 'lib/yarp/node.rb', line 2479

def name_loc
  @name_loc
end

#operator_locObject (readonly)

attr_reader operator_loc: Location?



2485
2486
2487
# File 'lib/yarp/node.rb', line 2485

def operator_loc
  @operator_loc
end

#valueObject (readonly)

attr_reader value: Node



2482
2483
2484
# File 'lib/yarp/node.rb', line 2482

def value
  @value
end

Instance Method Details

#accept(visitor) ⇒ Object

def accept: (visitor: Visitor) -> void



2497
2498
2499
# File 'lib/yarp/node.rb', line 2497

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

#child_nodesObject Also known as: deconstruct

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



2502
2503
2504
# File 'lib/yarp/node.rb', line 2502

def child_nodes
  [value]
end

#comment_targetsObject

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



2507
2508
2509
# File 'lib/yarp/node.rb', line 2507

def comment_targets
  [name_loc, value, *operator_loc]
end

#copy(**params) ⇒ Object

def copy: (**params) -> ClassVariableWriteNode



2512
2513
2514
2515
2516
2517
2518
2519
2520
# File 'lib/yarp/node.rb', line 2512

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



2526
2527
2528
# File 'lib/yarp/node.rb', line 2526

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

#inspect(inspector = NodeInspector.new) ⇒ Object



2535
2536
2537
2538
2539
2540
2541
2542
2543
# File 'lib/yarp/node.rb', line 2535

def inspect(inspector = NodeInspector.new)
  inspector << inspector.header(self)
  inspector << "├── name: #{name.inspect}\n"
  inspector << "├── name_loc: #{inspector.location(name_loc)}\n"
  inspector << "├── value:\n"
  inspector << inspector.child_node(value, "│   ")
  inspector << "└── operator_loc: #{inspector.location(operator_loc)}\n"
  inspector.to_str
end

#operatorObject

def operator: () -> String?



2531
2532
2533
# File 'lib/yarp/node.rb', line 2531

def operator
  operator_loc&.slice
end