Class: Prism::ConstantPathWriteNode

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

Overview

Represents writing to a constant path.

::Foo = 1
^^^^^^^^^

Foo::Bar = 1
^^^^^^^^^^^^

::Foo::Bar = 1
^^^^^^^^^^^^^^

Explore code sample

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

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

Initialize a new ConstantPathWriteNode node.

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

Parameters:



10030
10031
10032
10033
10034
10035
10036
10037
10038
# File 'lib/prism/node.rb', line 10030

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_write_node

See Node.type.

: () -> :constant_path_write_node

Returns:

  • (:constant_path_write_node)


10121
10122
10123
# File 'lib/prism/node.rb', line 10121

def self.type
  :constant_path_write_node
end

Instance Method Details

#===(other) ⇒ boolish

: (untyped other) -> boolish

Parameters:

  • other (Object)

Returns:

  • (boolish)


10213
10214
10215
10216
10217
10218
# File 'lib/prism/node.rb', line 10213

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


10054
10055
10056
# File 'lib/prism/node.rb', line 10054

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

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

See Node.child_nodes.

: () -> Array

Returns:

  • (Array[node?])


10061
10062
10063
# File 'lib/prism/node.rb', line 10061

def child_nodes
  [target, value]
end

#compact_child_nodes ⇒ Array[node]

See Node.compact_child_nodes.

: () -> Array

Returns:

  • (Array[node])


10079
10080
10081
# File 'lib/prism/node.rb', line 10079

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

:call-seq:

copy(**fields) -> ConstantPathWriteNode

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

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:



10089
10090
10091
# File 'lib/prism/node.rb', line 10089

def copy(node_id: self.node_id, location: self.location, flags: self.flags, target: self.target, operator_loc: self.operator_loc, value: self.value)
  ConstantPathWriteNode.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])


10096
10097
10098
10099
10100
10101
10102
10103
10104
10105
10106
10107
10108
10109
# File 'lib/prism/node.rb', line 10096

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)


10069
10070
10071
10072
10073
10074
# File 'lib/prism/node.rb', line 10069

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

  yield target
  yield value
end

#inspect ⇒ String

: () -> String

Returns:

  • (String)


10126
10127
10128
# File 'lib/prism/node.rb', line 10126

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

#newline_flag!(lines) ⇒ void

This method returns an undefined value.

: (Array lines) -> void

Parameters:

  • lines (Array[bool])


333
334
335
# File 'lib/prism/parse_result/newlines.rb', line 333

def newline_flag!(lines) # :nodoc:
  value.newline_flag!(lines)
end

#operator ⇒ String

:call-seq:

operator -> String

Slice the location of operator_loc from the source.

: () -> String

Returns:

  • (String)


10206
10207
10208
# File 'lib/prism/node.rb', line 10206

def operator
  operator_loc.slice
end

#operator_loc ⇒ Location

:category: Locations :call-seq:

operator_loc -> Location

The Location of the = operator.

::ABC = 123
      ^

Explore code sample

: () -> Location

Returns:



10166
10167
10168
10169
10170
# File 'lib/prism/node.rb', line 10166

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:



10177
10178
10179
# File 'lib/prism/node.rb', line 10177

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

#target ⇒ ConstantPathNode

:call-seq:

target -> ConstantPathNode

A node representing the constant path being written to.

Foo::Bar = 1
^^^^^^^^

::Foo = :abc
^^^^^

Explore code sample

: () -> ConstantPathNode

Returns:



10148
10149
10150
# File 'lib/prism/node.rb', line 10148

def target
  @target
end

#type ⇒ :constant_path_write_node

See Node#type.

: () -> :constant_path_write_node

Returns:

  • (:constant_path_write_node)


10114
10115
10116
# File 'lib/prism/node.rb', line 10114

def type
  :constant_path_write_node
end

#value ⇒ Prism::node

:call-seq:

value -> Node

The value to write to the constant path. It can be any non-void expression.

FOO::BAR = :abc
           ^^^^

Explore code sample

: () -> Prism::node

Returns:

  • (Prism::node)


10194
10195
10196
# File 'lib/prism/node.rb', line 10194

def value
  @value
end