Class: Prism::ClassVariableOperatorWriteNode

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 class variable 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) ⇒ ClassVariableOperatorWriteNode

Initialize a new ClassVariableOperatorWriteNode 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)


7467
7468
7469
7470
7471
7472
7473
7474
7475
7476
7477
# File 'lib/prism/node.rb', line 7467

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 ⇒ :class_variable_operator_write_node

See Node.type.

: () -> :class_variable_operator_write_node

Returns:

  • (:class_variable_operator_write_node)


7560
7561
7562
# File 'lib/prism/node.rb', line 7560

def self.type
  :class_variable_operator_write_node
end

Instance Method Details

#===(other) ⇒ boolish

: (untyped other) -> boolish

Parameters:

  • other (Object)

Returns:

  • (boolish)


7650
7651
7652
7653
7654
7655
7656
7657
# File 'lib/prism/node.rb', line 7650

def ===(other) # :nodoc:
  other.is_a?(ClassVariableOperatorWriteNode) &&
    (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)


7493
7494
7495
# File 'lib/prism/node.rb', line 7493

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

#binary_operator ⇒ Symbol

:call-seq:

binary_operator -> Symbol

Returns the binary_operator attribute.

: () -> Symbol

Returns:

  • (Symbol)


7641
7642
7643
# File 'lib/prism/node.rb', line 7641

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:



7610
7611
7612
7613
7614
# File 'lib/prism/node.rb', line 7610

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?])


7500
7501
7502
# File 'lib/prism/node.rb', line 7500

def child_nodes
  [value]
end

#compact_child_nodes ⇒ Array[node]

See Node.compact_child_nodes.

: () -> Array

Returns:

  • (Array[node])


7517
7518
7519
# File 'lib/prism/node.rb', line 7517

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

:call-seq:

copy(**fields) -> ClassVariableOperatorWriteNode

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) -> ClassVariableOperatorWriteNode

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:



7527
7528
7529
# File 'lib/prism/node.rb', line 7527

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)
  ClassVariableOperatorWriteNode.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])


7534
7535
7536
7537
7538
7539
7540
7541
7542
7543
7544
7545
7546
7547
7548
# File 'lib/prism/node.rb', line 7534

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)


206
207
208
# File 'lib/prism/desugar_compiler.rb', line 206

def desugar # :nodoc:
  DesugarOperatorWriteNode.new(self, source, :class_variable_read_node, :class_variable_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)


7508
7509
7510
7511
7512
# File 'lib/prism/node.rb', line 7508

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

  yield value
end

#inspect ⇒ String

: () -> String

Returns:

  • (String)


7565
7566
7567
# File 'lib/prism/node.rb', line 7565

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

#name ⇒ Symbol

:call-seq:

name -> Symbol

Returns the name attribute.

: () -> Symbol

Returns:

  • (Symbol)


7577
7578
7579
# File 'lib/prism/node.rb', line 7577

def name
  @name
end

#name_loc ⇒ Location

:category: Locations :call-seq:

name_loc -> Location

Returns the Location represented by name_loc.

: () -> Location

Returns:



7588
7589
7590
7591
7592
# File 'lib/prism/node.rb', line 7588

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:



7621
7622
7623
# File 'lib/prism/node.rb', line 7621

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:



7599
7600
7601
# File 'lib/prism/node.rb', line 7599

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

#type ⇒ :class_variable_operator_write_node

See Node#type.

: () -> :class_variable_operator_write_node

Returns:

  • (:class_variable_operator_write_node)


7553
7554
7555
# File 'lib/prism/node.rb', line 7553

def type
  :class_variable_operator_write_node
end

#value ⇒ Prism::node

:call-seq:

value -> Node

Returns the value attribute.

: () -> Prism::node

Returns:

  • (Prism::node)


7631
7632
7633
# File 'lib/prism/node.rb', line 7631

def value
  @value
end