Class: YARP::ConstantOperatorWriteNode

Inherits:
YARPNode
  • Object
show all
Defined in:
lib/yarp/node.rb,
ext/yarp/api_node.c

Overview

Represents assigning to a constant using an operator that isn’t ‘=`.

Target += value
^^^^^^^^^^^^^^^

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name_loc, operator_loc, value, operator, location) ⇒ ConstantOperatorWriteNode

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



1812
1813
1814
1815
1816
1817
1818
# File 'lib/yarp/node.rb', line 1812

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

Instance Attribute Details

#name_locObject (readonly)

attr_reader name_loc: Location



1800
1801
1802
# File 'lib/yarp/node.rb', line 1800

def name_loc
  @name_loc
end

#operatorObject (readonly)

attr_reader operator: Symbol



1809
1810
1811
# File 'lib/yarp/node.rb', line 1809

def operator
  @operator
end

#operator_locObject (readonly)

attr_reader operator_loc: Location



1803
1804
1805
# File 'lib/yarp/node.rb', line 1803

def operator_loc
  @operator_loc
end

#valueObject (readonly)

attr_reader value: Node



1806
1807
1808
# File 'lib/yarp/node.rb', line 1806

def value
  @value
end

Instance Method Details

#accept(visitor) ⇒ Object

def accept: (visitor: Visitor) -> void



1821
1822
1823
# File 'lib/yarp/node.rb', line 1821

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

#child_nodesObject Also known as: deconstruct

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



1826
1827
1828
# File 'lib/yarp/node.rb', line 1826

def child_nodes
  [value]
end

#copy(**params) ⇒ Object

def copy: (**params) -> ConstantOperatorWriteNode



1831
1832
1833
1834
1835
1836
1837
1838
1839
# File 'lib/yarp/node.rb', line 1831

def copy(**params)
  ConstantOperatorWriteNode.new(
    params.fetch(:name_loc) { name_loc },
    params.fetch(:operator_loc) { operator_loc },
    params.fetch(:value) { value },
    params.fetch(:operator) { operator },
    params.fetch(:location) { location },
  )
end

#deconstruct_keys(keys) ⇒ Object

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



1845
1846
1847
# File 'lib/yarp/node.rb', line 1845

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

#nameObject

def name: () -> String



1850
1851
1852
# File 'lib/yarp/node.rb', line 1850

def name
  name_loc.slice
end