Class: YARP::ConstantOrWriteNode

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 constant.

Target ||= value
^^^^^^^^^^^^^^^^

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name_loc, operator_loc, value, location) ⇒ ConstantOrWriteNode

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



1870
1871
1872
1873
1874
1875
# File 'lib/yarp/node.rb', line 1870

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



1861
1862
1863
# File 'lib/yarp/node.rb', line 1861

def name_loc
  @name_loc
end

#operator_locObject (readonly)

attr_reader operator_loc: Location



1864
1865
1866
# File 'lib/yarp/node.rb', line 1864

def operator_loc
  @operator_loc
end

#valueObject (readonly)

attr_reader value: Node



1867
1868
1869
# File 'lib/yarp/node.rb', line 1867

def value
  @value
end

Instance Method Details

#accept(visitor) ⇒ Object

def accept: (visitor: Visitor) -> void



1878
1879
1880
# File 'lib/yarp/node.rb', line 1878

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

#child_nodesObject Also known as: deconstruct

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



1883
1884
1885
# File 'lib/yarp/node.rb', line 1883

def child_nodes
  [value]
end

#copy(**params) ⇒ Object

def copy: (**params) -> ConstantOrWriteNode



1888
1889
1890
1891
1892
1893
1894
1895
# File 'lib/yarp/node.rb', line 1888

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



1901
1902
1903
# File 'lib/yarp/node.rb', line 1901

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

#nameObject

def name: () -> String



1906
1907
1908
# File 'lib/yarp/node.rb', line 1906

def name
  name_loc.slice
end

#operatorObject

def operator: () -> String



1911
1912
1913
# File 'lib/yarp/node.rb', line 1911

def operator
  operator_loc.slice
end