Class: YARP::InstanceVariableAndWriteNode

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 an instance variable.

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

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



5348
5349
5350
5351
5352
5353
5354
# File 'lib/yarp/node.rb', line 5348

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



5336
5337
5338
# File 'lib/yarp/node.rb', line 5336

def name
  @name
end

#name_locObject (readonly)

attr_reader name_loc: Location



5339
5340
5341
# File 'lib/yarp/node.rb', line 5339

def name_loc
  @name_loc
end

#operator_locObject (readonly)

attr_reader operator_loc: Location



5342
5343
5344
# File 'lib/yarp/node.rb', line 5342

def operator_loc
  @operator_loc
end

#valueObject (readonly)

attr_reader value: Node



5345
5346
5347
# File 'lib/yarp/node.rb', line 5345

def value
  @value
end

Instance Method Details

#accept(visitor) ⇒ Object

def accept: (visitor: Visitor) -> void



5357
5358
5359
# File 'lib/yarp/node.rb', line 5357

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

#child_nodesObject Also known as: deconstruct

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



5362
5363
5364
# File 'lib/yarp/node.rb', line 5362

def child_nodes
  [value]
end

#comment_targetsObject

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



5367
5368
5369
# File 'lib/yarp/node.rb', line 5367

def comment_targets
  [name_loc, operator_loc, value]
end

#copy(**params) ⇒ Object

def copy: (**params) -> InstanceVariableAndWriteNode



5372
5373
5374
5375
5376
5377
5378
5379
5380
# File 'lib/yarp/node.rb', line 5372

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



5386
5387
5388
# File 'lib/yarp/node.rb', line 5386

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

#inspect(inspector = NodeInspector.new) ⇒ Object



5395
5396
5397
5398
5399
5400
5401
5402
5403
# File 'lib/yarp/node.rb', line 5395

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



5391
5392
5393
# File 'lib/yarp/node.rb', line 5391

def operator
  operator_loc.slice
end