Class: YARP::LocalVariableAndWriteNode

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

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name_loc, operator_loc, value, name, depth, location) ⇒ LocalVariableAndWriteNode

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



6471
6472
6473
6474
6475
6476
6477
6478
# File 'lib/yarp/node.rb', line 6471

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

Instance Attribute Details

#depthObject (readonly)

attr_reader depth: Integer



6468
6469
6470
# File 'lib/yarp/node.rb', line 6468

def depth
  @depth
end

#nameObject (readonly)

attr_reader name: Symbol



6465
6466
6467
# File 'lib/yarp/node.rb', line 6465

def name
  @name
end

#name_locObject (readonly)

attr_reader name_loc: Location



6456
6457
6458
# File 'lib/yarp/node.rb', line 6456

def name_loc
  @name_loc
end

#operator_locObject (readonly)

attr_reader operator_loc: Location



6459
6460
6461
# File 'lib/yarp/node.rb', line 6459

def operator_loc
  @operator_loc
end

#valueObject (readonly)

attr_reader value: Node



6462
6463
6464
# File 'lib/yarp/node.rb', line 6462

def value
  @value
end

Instance Method Details

#accept(visitor) ⇒ Object

def accept: (visitor: Visitor) -> void



6481
6482
6483
# File 'lib/yarp/node.rb', line 6481

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

#child_nodesObject Also known as: deconstruct

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



6486
6487
6488
# File 'lib/yarp/node.rb', line 6486

def child_nodes
  [value]
end

#comment_targetsObject

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



6491
6492
6493
# File 'lib/yarp/node.rb', line 6491

def comment_targets
  [name_loc, operator_loc, value]
end

#copy(**params) ⇒ Object

def copy: (**params) -> LocalVariableAndWriteNode



6496
6497
6498
6499
6500
6501
6502
6503
6504
6505
# File 'lib/yarp/node.rb', line 6496

def copy(**params)
  LocalVariableAndWriteNode.new(
    params.fetch(:name_loc) { name_loc },
    params.fetch(:operator_loc) { operator_loc },
    params.fetch(:value) { value },
    params.fetch(:name) { name },
    params.fetch(:depth) { depth },
    params.fetch(:location) { location },
  )
end

#deconstruct_keys(keys) ⇒ Object

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



6511
6512
6513
# File 'lib/yarp/node.rb', line 6511

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

#inspect(inspector = NodeInspector.new) ⇒ Object



6520
6521
6522
6523
6524
6525
6526
6527
6528
6529
# File 'lib/yarp/node.rb', line 6520

def inspect(inspector = NodeInspector.new)
  inspector << inspector.header(self)
  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 << "├── name: #{name.inspect}\n"
  inspector << "└── depth: #{depth.inspect}\n"
  inspector.to_str
end

#operatorObject

def operator: () -> String



6516
6517
6518
# File 'lib/yarp/node.rb', line 6516

def operator
  operator_loc.slice
end