123456789_123456789_123456789_123456789_123456789_

Class: Prism::ConstantPathNode

Relationships & Source Files
Namespace Children
Exceptions:
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
self, Node
Instance Chain:
self, Node
Inherits: Prism::Node
Defined in: lib/prism/node_ext.rb

Instance Attribute Summary

Node - Inherited

Instance Method Summary

  • #child

    Previously, we had a child node on this class that contained either a constant read or a missing node.

  • #full_name

    Returns the full name of this constant path.

  • #full_name_parts

    Returns the list of parts for the full name of this constant path.

Node - Inherited

Instance Method Details

#child

Previously, we had a child node on this class that contained either a constant read or a missing node. To not cause a breaking change, we continue to supply that API.

[ GitHub ]

  
# File 'lib/prism/node_ext.rb', line 202

def child
  deprecated("name", "name_loc")

  if name
    ConstantReadNode.new(source, -1, name_loc, 0, name)
  else
    MissingNode.new(source, -1, location, 0)
  end
end

#full_name

Returns the full name of this constant path. For example: “Foo::Bar”

[ GitHub ]

  
# File 'lib/prism/node_ext.rb', line 195

def full_name
  full_name_parts.join("::")
end

#full_name_parts

Returns the list of parts for the full name of this constant path. For example: [:Foo, :Bar]

[ GitHub ]

  
# File 'lib/prism/node_ext.rb', line 173

def full_name_parts
  parts = [] #: Array[Symbol]
  current = self #: node?

  while current.is_a?(ConstantPathNode)
    name = current.name
    if name.nil?
      raise MissingNodesInConstantPathError, "Constant path contains missing nodes. Cannot compute full name"
    end

    parts.unshift(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