Class: Prism::ConstantPathNode

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

Defined Under Namespace

Classes: DynamicPartsInConstantPathError, MissingNodesInConstantPathError

Instance Method Summary collapse

Methods inherited from Node

#deprecated, #newline_flag!, #newline_flag?

Instance Method Details

#childObject

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.



202
203
204
205
206
207
208
209
210
# 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_nameObject

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



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

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]



173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
# 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