class Prism::ConstantPathNode

Experimental RBS support (using type sampling data from the type_fusion project).

# sig/prism/node.rbs

class Prism::ConstantPathNode < Prism::Node
  def accept: (Analyzer::Visitor visitor) -> (Array[Prism::LocalVariableReadNode] | Array[Prism::ConstantReadNode] | Array[Prism::ConstantPathNode])
  def compact_child_nodes: () -> (Array[Prism::ConstantReadNode] | Array[Prism::ConstantPathNode])
  def initialize: ((Prism::ConstantReadNode | Prism::ConstantPathNode) parent, Prism::ConstantReadNode child, Prism::Location delimiter_loc, Prism::Location location) -> void
end

^^^^^^^^
Foo::Bar
Represents accessing a constant through a path of ‘::` operators.

def self.type

def self.type: () -> Symbol

class, but should be faster in a case statement or an array comparison.
Note that like #type, it will still be slower than using == for a single
splitting on the type of the node without having to do a long === chain.
Similar to #type, this method returns a symbol that you can use for
def self.type
  :constant_path_node
end

def accept(visitor)

Experimental RBS support (using type sampling data from the type_fusion project).

def accept: (Analyzer::Visitor visitor) -> Prism::ConstantReadNode

This signature was generated using 6 samples from 1 application.

def accept: (Visitor visitor) -> void
def accept(visitor)
  visitor.visit_constant_path_node(self)
end

def child_nodes

def child_nodes: () -> Array[nil | Node]
def child_nodes
  [parent, child]
end

def comment_targets

def comment_targets: () -> Array[Node | Location]
def comment_targets
  [*parent, child, delimiter_loc]
end

def compact_child_nodes

Experimental RBS support (using type sampling data from the type_fusion project).

def compact_child_nodes: () -> (Prism::ConstantReadNode | )

This signature was generated using 11 samples from 1 application.

def compact_child_nodes: () -> Array[Node]
def compact_child_nodes
  compact = []
  compact << parent if parent
  compact << child
  compact
end

def copy(**params)

def copy: (**params) -> ConstantPathNode
def copy(**params)
  ConstantPathNode.new(
    params.fetch(:parent) { parent },
    params.fetch(:child) { child },
    params.fetch(:delimiter_loc) { delimiter_loc },
    params.fetch(:location) { location },
  )
end

def deconstruct_keys(keys)

def deconstruct_keys: (Array[Symbol] keys) -> { parent: Node?, child: Node, delimiter_loc: Location, location: Location }
def deconstruct_keys(keys)
  { parent: parent, child: child, delimiter_loc: delimiter_loc, location: location }
end

def delimiter

def delimiter: () -> String
def delimiter
  delimiter_loc.slice
end

def full_name

Returns the full name of this constant path. For example: "Foo::Bar"
def full_name
  full_name_parts.join("::")
end

def full_name_parts

For example: [:Foo, :Bar]
Returns the list of parts for the full name of this constant path.
def full_name_parts
  parts = [child.name]
  current = parent
  while current.is_a?(ConstantPathNode)
    parts.unshift(current.child.name)
    current = current.parent
  end
  if !current.is_a?(ConstantReadNode) && !current.nil?
    raise DynamicPartsInConstantPathError, "Constant path contains dynamic parts. Cannot compute full name"
  end
  parts.unshift(current&.name || :"")
end

def initialize(parent, child, delimiter_loc, location)

Experimental RBS support (using type sampling data from the type_fusion project).

def initialize: ((Prism::ConstantReadNode | Prism::ConstantPathNode) parent, Prism::ConstantReadNode child, Prism::Location delimiter_loc, Prism::Location location) -> void

This signature was generated using 6 samples from 1 application.

def initialize: (Node? parent, Node child, Location delimiter_loc, Location location) -> void
def initialize(parent, child, delimiter_loc, location)
  @newline = false
  @parent = parent
  @child = child
  @delimiter_loc = delimiter_loc
  @location = location
end

def inspect(inspector = NodeInspector.new)

def inspect(NodeInspector inspector) -> String
def inspect(inspector = NodeInspector.new)
  inspector << inspector.header(self)
  if (parent = self.parent).nil?
    inspector << "├── parent: ∅\n"
  else
    inspector << "├── parent:\n"
    inspector << parent.inspect(inspector.child_inspector("│   ")).delete_prefix(inspector.prefix)
  end
  inspector << "├── child:\n"
  inspector << inspector.child_node(child, "│   ")
  inspector << "└── delimiter_loc: #{inspector.location(delimiter_loc)}\n"
  inspector.to_str
end

def type

def type: () -> Symbol

keys will use a jump table.
you can take advantage of the fact that case statements with all symbol
it uses a single integer comparison, but also because if you're on CRuby
can use for comparison. This is faster than the other approaches because
Instead, you can call #type, which will return to you a symbol that you

method calls, and/or array allocations.
these approaches are relatively slow because of the constant lookups,
case statement and doing `case node; when cls1; when cls2; end`. Both of
calling `[cls1, cls2].include?(node.class)` or putting the node into a
classes to see what kind of behavior to perform. Usually this is done by
Sometimes you want to check an instance of a node against a list of
def type
  :constant_path_node
end