Class: YARP::GlobalVariableOrWriteNode

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_loc, operator_loc, value, location) ⇒ GlobalVariableOrWriteNode

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



3391
3392
3393
3394
3395
3396
# File 'lib/yarp/node.rb', line 3391

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

Instance Attribute Details

#name_locObject (readonly)

attr_reader name_loc: Location



3382
3383
3384
# File 'lib/yarp/node.rb', line 3382

def name_loc
  @name_loc
end

#operator_locObject (readonly)

attr_reader operator_loc: Location



3385
3386
3387
# File 'lib/yarp/node.rb', line 3385

def operator_loc
  @operator_loc
end

#valueObject (readonly)

attr_reader value: Node



3388
3389
3390
# File 'lib/yarp/node.rb', line 3388

def value
  @value
end

Instance Method Details

#accept(visitor) ⇒ Object

def accept: (visitor: Visitor) -> void



3399
3400
3401
# File 'lib/yarp/node.rb', line 3399

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

#child_nodesObject Also known as: deconstruct

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



3404
3405
3406
# File 'lib/yarp/node.rb', line 3404

def child_nodes
  [value]
end

#copy(**params) ⇒ Object

def copy: (**params) -> GlobalVariableOrWriteNode



3409
3410
3411
3412
3413
3414
3415
3416
# File 'lib/yarp/node.rb', line 3409

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



3422
3423
3424
# File 'lib/yarp/node.rb', line 3422

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

#nameObject

def name: () -> String



3427
3428
3429
# File 'lib/yarp/node.rb', line 3427

def name
  name_loc.slice
end

#operatorObject

def operator: () -> String



3432
3433
3434
# File 'lib/yarp/node.rb', line 3432

def operator
  operator_loc.slice
end