Class: YARP::GlobalVariableOperatorOrWriteNode

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) ⇒ GlobalVariableOperatorOrWriteNode

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



2645
2646
2647
2648
2649
2650
# File 'lib/yarp/node.rb', line 2645

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



2636
2637
2638
# File 'lib/yarp/node.rb', line 2636

def name_loc
  @name_loc
end

#operator_locObject (readonly)

attr_reader operator_loc: Location



2639
2640
2641
# File 'lib/yarp/node.rb', line 2639

def operator_loc
  @operator_loc
end

#valueObject (readonly)

attr_reader value: Node



2642
2643
2644
# File 'lib/yarp/node.rb', line 2642

def value
  @value
end

Instance Method Details

#accept(visitor) ⇒ Object

def accept: (visitor: Visitor) -> void



2653
2654
2655
# File 'lib/yarp/node.rb', line 2653

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

#child_nodesObject Also known as: deconstruct

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



2659
2660
2661
# File 'lib/yarp/node.rb', line 2659

def child_nodes
  [value]
end

#deconstruct_keys(keys) ⇒ Object

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



2667
2668
2669
# File 'lib/yarp/node.rb', line 2667

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

#nameObject

def name: () -> String



2672
2673
2674
# File 'lib/yarp/node.rb', line 2672

def name
  name_loc.slice
end

#operatorObject

def operator: () -> String



2677
2678
2679
# File 'lib/yarp/node.rb', line 2677

def operator
  operator_loc.slice
end