Class: Prism::ConstantOperatorWriteNode

Inherits:
PrismNode
  • Object
show all
Defined in:
lib/prism/node.rb,
lib/prism/desugar_compiler.rb,
sig/generated/prism/node.rbs,
sig/generated/prism/desugar_compiler.rbs,
ext/prism/api_node.c

Overview

Represents assigning to a constant using an operator that isn't =.

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

Explore code sample

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source, node_id, location, flags, name, name_loc, binary_operator_loc, value, binary_operator) ⇒ ConstantOperatorWriteNode

Initialize a new ConstantOperatorWriteNode node.

: (Source source, Integer node_id, Location location, Integer flags, Symbol name, Location name_loc, Location binary_operator_loc, Prism::node value, Symbol binary_operator) -> void

Parameters:

  • source (Source)
  • node_id (Integer)
  • location (Location)
  • flags (Integer)
  • name (Symbol)
  • name_loc (Location)
  • binary_operator_loc (Location)
  • value (Prism::node)
  • binary_operator (Symbol)


8602
8603
8604
8605
8606
8607
8608
8609
8610
8611
8612
# File 'lib/prism/node.rb', line 8602

def initialize(source, node_id, location, flags, name, name_loc, binary_operator_loc, value, binary_operator)
  @source = source
  @node_id = node_id
  @location = location
  @flags = flags
  @name = name
  @name_loc = name_loc
  @binary_operator_loc = binary_operator_loc
  @value = value
  @binary_operator = binary_operator
end

Class Method Details

.type ⇒ :constant_operator_write_node

See Node.type.

: () -> :constant_operator_write_node

Returns:

  • (:constant_operator_write_node)


8695
8696
8697
# File 'lib/prism/node.rb', line 8695

def self.type
  :constant_operator_write_node
end

Instance Method Details

#===(other) ⇒ boolish

: (untyped other) -> boolish

Parameters:

  • other (Object)

Returns:

  • (boolish)


8785
8786
8787
8788
8789
8790
8791
8792
# File 'lib/prism/node.rb', line 8785

def ===(other) # :nodoc:
  other.is_a?(ConstantOperatorWriteNode) &&
    (name === other.name) &&
    (name_loc.nil? == other.name_loc.nil?) &&
    (binary_operator_loc.nil? == other.binary_operator_loc.nil?) &&
    (value === other.value) &&
    (binary_operator === other.binary_operator)
end

#accept(visitor) ⇒ Object

See Node.accept.

: (_Visitor visitor) -> untyped

Parameters:

Returns:

  • (Object)


8628
8629
8630
# File 'lib/prism/node.rb', line 8628

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

#binary_operator ⇒ Symbol

:call-seq:

binary_operator -> Symbol

Returns the binary_operator attribute.

: () -> Symbol

Returns:

  • (Symbol)


8776
8777
8778
# File 'lib/prism/node.rb', line 8776

def binary_operator
  @binary_operator
end

#binary_operator_loc ⇒ Location

:category: Locations :call-seq:

binary_operator_loc -> Location

Returns the Location represented by binary_operator_loc.

: () -> Location

Returns:



8745
8746
8747
8748
8749
# File 'lib/prism/node.rb', line 8745

def binary_operator_loc
  location = @binary_operator_loc
  return location if location.is_a?(Location)
  @binary_operator_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
end

#child_nodes ⇒ Array[node?] Also known as: deconstruct

See Node.child_nodes.

: () -> Array

Returns:

  • (Array[node?])


8635
8636
8637
# File 'lib/prism/node.rb', line 8635

def child_nodes
  [value]
end

#compact_child_nodes ⇒ Array[node]

See Node.compact_child_nodes.

: () -> Array

Returns:

  • (Array[node])


8652
8653
8654
# File 'lib/prism/node.rb', line 8652

def compact_child_nodes
  [value]
end

#copy(node_id: self.node_id, location: self.location, flags: self.flags, name: self.name, name_loc: self.name_loc, binary_operator_loc: self.binary_operator_loc, value: self.value, binary_operator: self.binary_operator) ⇒ ConstantOperatorWriteNode

:call-seq:

copy(**fields) -> ConstantOperatorWriteNode

Creates a copy of self with the given fields, using self as the template.

: (?node_id: Integer, ?location: Location, ?flags: Integer, ?name: Symbol, ?name_loc: Location, ?binary_operator_loc: Location, ?value: Prism::node, ?binary_operator: Symbol) -> ConstantOperatorWriteNode

Parameters:

  • node_id: (Integer) (defaults to: self.node_id)
  • location: (Location) (defaults to: self.location)
  • flags: (Integer) (defaults to: self.flags)
  • name: (Symbol) (defaults to: self.name)
  • name_loc: (Location) (defaults to: self.name_loc)
  • binary_operator_loc: (Location) (defaults to: self.binary_operator_loc)
  • value: (Prism::node) (defaults to: self.value)
  • binary_operator: (Symbol) (defaults to: self.binary_operator)

Returns:



8662
8663
8664
# File 'lib/prism/node.rb', line 8662

def copy(node_id: self.node_id, location: self.location, flags: self.flags, name: self.name, name_loc: self.name_loc, binary_operator_loc: self.binary_operator_loc, value: self.value, binary_operator: self.binary_operator)
  ConstantOperatorWriteNode.new(source, node_id, location, flags, name, name_loc, binary_operator_loc, value, binary_operator)
end

#deconstruct_keys(keys) ⇒ Hash[Symbol, untyped]

: (Array? keys) -> Hash[Symbol, untyped]

Parameters:

  • keys (Array[Symbol], nil)

Returns:

  • (Hash[Symbol, untyped])


8669
8670
8671
8672
8673
8674
8675
8676
8677
8678
8679
8680
8681
8682
8683
# File 'lib/prism/node.rb', line 8669

def deconstruct_keys(keys) # :nodoc:
  (keys || %i[node_id location name name_loc binary_operator_loc value binary_operator]).each_with_object(
    {} #: Hash[Symbol, untyped]
  ) do |key, deconstructed|
    case key
    when :node_id                 then deconstructed[:node_id] = self.node_id
    when :location                then deconstructed[:location] = self.location
    when :name                    then deconstructed[:name] = self.name
    when :name_loc                then deconstructed[:name_loc] = self.name_loc
    when :binary_operator_loc     then deconstructed[:binary_operator_loc] = self.binary_operator_loc
    when :value                   then deconstructed[:value] = self.value
    when :binary_operator         then deconstructed[:binary_operator] = self.binary_operator
    end
  end
end

#desugar ⇒ node

: () -> node

Returns:

  • (node)


227
228
229
# File 'lib/prism/desugar_compiler.rb', line 227

def desugar # :nodoc:
  DesugarOperatorWriteNode.new(self, source, :constant_read_node, :constant_write_node, name: name).compile
end

#each_child_node ⇒ Enumerator[node, void] #each_child_node ⇒ void

See Node.each_child_node.

: () -> Enumerator[node, void] : () { (node) -> void } -> void

Overloads:

  • #each_child_node ⇒ Enumerator[node, void]

    Returns:

    • (Enumerator[node, void])
  • #each_child_node ⇒ void

    This method returns an undefined value.

Yields:

Yield Parameters:

  • arg0 (node)

Yield Returns:

  • (void)


8643
8644
8645
8646
8647
# File 'lib/prism/node.rb', line 8643

def each_child_node(&blk)
  return to_enum(:each_child_node) unless block_given?

  yield value
end

#inspect ⇒ String

: () -> String

Returns:

  • (String)


8700
8701
8702
# File 'lib/prism/node.rb', line 8700

def inspect # :nodoc:
  InspectVisitor.compose(self)
end

#name ⇒ Symbol

:call-seq:

name -> Symbol

Returns the name attribute.

: () -> Symbol

Returns:

  • (Symbol)


8712
8713
8714
# File 'lib/prism/node.rb', line 8712

def name
  @name
end

#name_loc ⇒ Location

:category: Locations :call-seq:

name_loc -> Location

Returns the Location represented by name_loc.

: () -> Location

Returns:



8723
8724
8725
8726
8727
# File 'lib/prism/node.rb', line 8723

def name_loc
  location = @name_loc
  return location if location.is_a?(Location)
  @name_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
end

#save_binary_operator_loc(repository) ⇒ Relocation::Entry

:category: Repository Save the binary_operator_loc location using the given saved source so that it can be retrieved later.

: (_Repository repository) -> Relocation::Entry

Parameters:

Returns:



8756
8757
8758
# File 'lib/prism/node.rb', line 8756

def save_binary_operator_loc(repository)
  repository.enter(node_id, :binary_operator_loc)
end

#save_name_loc(repository) ⇒ Relocation::Entry

:category: Repository Save the name_loc location using the given saved source so that it can be retrieved later.

: (_Repository repository) -> Relocation::Entry

Parameters:

Returns:



8734
8735
8736
# File 'lib/prism/node.rb', line 8734

def save_name_loc(repository)
  repository.enter(node_id, :name_loc)
end

#type ⇒ :constant_operator_write_node

See Node#type.

: () -> :constant_operator_write_node

Returns:

  • (:constant_operator_write_node)


8688
8689
8690
# File 'lib/prism/node.rb', line 8688

def type
  :constant_operator_write_node
end

#value ⇒ Prism::node

:call-seq:

value -> Node

Returns the value attribute.

: () -> Prism::node

Returns:

  • (Prism::node)


8766
8767
8768
# File 'lib/prism/node.rb', line 8766

def value
  @value
end