Class: YARP::GlobalVariableAndWriteNode

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

$target &&= value
^^^^^^^^^^^^^^^^^

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

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



4523
4524
4525
4526
4527
4528
4529
# File 'lib/yarp/node.rb', line 4523

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



4511
4512
4513
# File 'lib/yarp/node.rb', line 4511

def name
  @name
end

#name_locObject (readonly)

attr_reader name_loc: Location



4514
4515
4516
# File 'lib/yarp/node.rb', line 4514

def name_loc
  @name_loc
end

#operator_locObject (readonly)

attr_reader operator_loc: Location



4517
4518
4519
# File 'lib/yarp/node.rb', line 4517

def operator_loc
  @operator_loc
end

#valueObject (readonly)

attr_reader value: Node



4520
4521
4522
# File 'lib/yarp/node.rb', line 4520

def value
  @value
end

Instance Method Details

#accept(visitor) ⇒ Object

def accept: (visitor: Visitor) -> void



4532
4533
4534
# File 'lib/yarp/node.rb', line 4532

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

#child_nodesObject Also known as: deconstruct

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



4537
4538
4539
# File 'lib/yarp/node.rb', line 4537

def child_nodes
  [value]
end

#comment_targetsObject

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



4542
4543
4544
# File 'lib/yarp/node.rb', line 4542

def comment_targets
  [name_loc, operator_loc, value]
end

#copy(**params) ⇒ Object

def copy: (**params) -> GlobalVariableAndWriteNode



4547
4548
4549
4550
4551
4552
4553
4554
4555
# File 'lib/yarp/node.rb', line 4547

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



4561
4562
4563
# File 'lib/yarp/node.rb', line 4561

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

#inspect(inspector = NodeInspector.new) ⇒ Object



4570
4571
4572
4573
4574
4575
4576
4577
4578
# File 'lib/yarp/node.rb', line 4570

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

#operatorObject

def operator: () -> String



4566
4567
4568
# File 'lib/yarp/node.rb', line 4566

def operator
  operator_loc.slice
end