Class: Prism::ConstantPathAndWriteNode

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

Overview

Represents the use of the &&= operator for assignment to a constant path.

Parent::Child &&= value
^^^^^^^^^^^^^^^^^^^^^^^

Explore code sample

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source, node_id, location, flags, target, operator_loc, value) ⇒ ConstantPathAndWriteNode

Initialize a new ConstantPathAndWriteNode node.

: (Source source, Integer node_id, Location location, Integer flags, ConstantPathNode target, Location operator_loc, Prism::node value) -> void

Parameters:



9019
9020
9021
9022
9023
9024
9025
9026
9027
# File 'lib/prism/node.rb', line 9019

def initialize(source, node_id, location, flags, target, operator_loc, value)
  @source = source
  @node_id = node_id
  @location = location
  @flags = flags
  @target = target
  @operator_loc = operator_loc
  @value = value
end

Class Method Details

.type ⇒ :constant_path_and_write_node

See Node.type.

: () -> :constant_path_and_write_node

Returns:

  • (:constant_path_and_write_node)


9110
9111
9112
# File 'lib/prism/node.rb', line 9110

def self.type
  :constant_path_and_write_node
end

Instance Method Details

#===(other) ⇒ boolish

: (untyped other) -> boolish

Parameters:

  • other (Object)

Returns:

  • (boolish)


9178
9179
9180
9181
9182
9183
# File 'lib/prism/node.rb', line 9178

def ===(other) # :nodoc:
  other.is_a?(ConstantPathAndWriteNode) &&
    (target === other.target) &&
    (operator_loc.nil? == other.operator_loc.nil?) &&
    (value === other.value)
end

#accept(visitor) ⇒ Object

See Node.accept.

: (_Visitor visitor) -> untyped

Parameters:

Returns:

  • (Object)


9043
9044
9045
# File 'lib/prism/node.rb', line 9043

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

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

See Node.child_nodes.

: () -> Array

Returns:

  • (Array[node?])


9050
9051
9052
# File 'lib/prism/node.rb', line 9050

def child_nodes
  [target, value]
end

#compact_child_nodes ⇒ Array[node]

See Node.compact_child_nodes.

: () -> Array

Returns:

  • (Array[node])


9068
9069
9070
# File 'lib/prism/node.rb', line 9068

def compact_child_nodes
  [target, value]
end

#copy(node_id: self.node_id, location: self.location, flags: self.flags, target: self.target, operator_loc: self.operator_loc, value: self.value) ⇒ ConstantPathAndWriteNode

:call-seq:

copy(**fields) -> ConstantPathAndWriteNode

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

: (?node_id: Integer, ?location: Location, ?flags: Integer, ?target: ConstantPathNode, ?operator_loc: Location, ?value: Prism::node) -> ConstantPathAndWriteNode

Parameters:

  • node_id: (Integer) (defaults to: self.node_id)
  • location: (Location) (defaults to: self.location)
  • flags: (Integer) (defaults to: self.flags)
  • target: (ConstantPathNode) (defaults to: self.target)
  • operator_loc: (Location) (defaults to: self.operator_loc)
  • value: (Prism::node) (defaults to: self.value)

Returns:



9078
9079
9080
# File 'lib/prism/node.rb', line 9078

def copy(node_id: self.node_id, location: self.location, flags: self.flags, target: self.target, operator_loc: self.operator_loc, value: self.value)
  ConstantPathAndWriteNode.new(source, node_id, location, flags, target, operator_loc, value)
end

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

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

Parameters:

  • keys (Array[Symbol], nil)

Returns:

  • (Hash[Symbol, untyped])


9085
9086
9087
9088
9089
9090
9091
9092
9093
9094
9095
9096
9097
9098
# File 'lib/prism/node.rb', line 9085

def deconstruct_keys(keys) # :nodoc:
  (keys || %i[node_id location target operator_loc value 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 :target                  then deconstructed[:target] = self.target
    when :operator_loc            then deconstructed[:operator_loc] = self.operator_loc
    when :value                   then deconstructed[:value] = self.value
    when :operator                then deconstructed[:operator] = self.operator
    end
  end
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)


9058
9059
9060
9061
9062
9063
# File 'lib/prism/node.rb', line 9058

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

  yield target
  yield value
end

#inspect ⇒ String

: () -> String

Returns:

  • (String)


9115
9116
9117
# File 'lib/prism/node.rb', line 9115

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

#operator ⇒ String

:call-seq:

operator -> String

Slice the location of operator_loc from the source.

: () -> String

Returns:

  • (String)


9171
9172
9173
# File 'lib/prism/node.rb', line 9171

def operator
  operator_loc.slice
end

#operator_loc ⇒ Location

:category: Locations :call-seq:

operator_loc -> Location

Returns the Location represented by operator_loc.

: () -> Location

Returns:



9138
9139
9140
9141
9142
# File 'lib/prism/node.rb', line 9138

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

#save_operator_loc(repository) ⇒ Relocation::Entry

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

: (_Repository repository) -> Relocation::Entry

Parameters:

Returns:



9149
9150
9151
# File 'lib/prism/node.rb', line 9149

def save_operator_loc(repository)
  repository.enter(node_id, :operator_loc)
end

#target ⇒ ConstantPathNode

:call-seq:

target -> ConstantPathNode

Returns the target attribute.

: () -> ConstantPathNode

Returns:



9127
9128
9129
# File 'lib/prism/node.rb', line 9127

def target
  @target
end

#type ⇒ :constant_path_and_write_node

See Node#type.

: () -> :constant_path_and_write_node

Returns:

  • (:constant_path_and_write_node)


9103
9104
9105
# File 'lib/prism/node.rb', line 9103

def type
  :constant_path_and_write_node
end

#value ⇒ Prism::node

:call-seq:

value -> Node

Returns the value attribute.

: () -> Prism::node

Returns:

  • (Prism::node)


9159
9160
9161
# File 'lib/prism/node.rb', line 9159

def value
  @value
end