Class: YARP::LocalVariableOperatorOrWriteNode

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, constant_id, location) ⇒ LocalVariableOperatorOrWriteNode

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



3837
3838
3839
3840
3841
3842
3843
# File 'lib/yarp/node.rb', line 3837

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

Instance Attribute Details

#constant_idObject (readonly)

attr_reader constant_id: Symbol



3834
3835
3836
# File 'lib/yarp/node.rb', line 3834

def constant_id
  @constant_id
end

#name_locObject (readonly)

attr_reader name_loc: Location



3825
3826
3827
# File 'lib/yarp/node.rb', line 3825

def name_loc
  @name_loc
end

#operator_locObject (readonly)

attr_reader operator_loc: Location



3828
3829
3830
# File 'lib/yarp/node.rb', line 3828

def operator_loc
  @operator_loc
end

#valueObject (readonly)

attr_reader value: Node



3831
3832
3833
# File 'lib/yarp/node.rb', line 3831

def value
  @value
end

Instance Method Details

#accept(visitor) ⇒ Object

def accept: (visitor: Visitor) -> void



3846
3847
3848
# File 'lib/yarp/node.rb', line 3846

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

#child_nodesObject Also known as: deconstruct

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



3852
3853
3854
# File 'lib/yarp/node.rb', line 3852

def child_nodes
  [value]
end

#deconstruct_keys(keys) ⇒ Object

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



3860
3861
3862
# File 'lib/yarp/node.rb', line 3860

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

#nameObject

def name: () -> String



3865
3866
3867
# File 'lib/yarp/node.rb', line 3865

def name
  name_loc.slice
end

#operatorObject

def operator: () -> String



3870
3871
3872
# File 'lib/yarp/node.rb', line 3870

def operator
  operator_loc.slice
end