Class: Prism::ConstantPathNode

Inherits:
Node
  • Object
show all
Defined in:
lib/prism/node_ext.rb

Defined Under Namespace

Classes: DynamicPartsInConstantPathError

Instance Method Summary collapse

Instance Method Details

#full_nameObject

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



129
130
131
# File 'lib/prism/node_ext.rb', line 129

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

#full_name_partsObject

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



112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/prism/node_ext.rb', line 112

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