Class: Prism::ConstantPathTargetNode

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

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.



243
244
245
246
247
248
249
250
251
# File 'lib/prism/node_ext.rb', line 243

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”



236
237
238
# File 'lib/prism/node_ext.rb', line 236

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]



216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
# File 'lib/prism/node_ext.rb', line 216

def full_name_parts
  parts =
    case parent
    when ConstantPathNode, ConstantReadNode
      parent.full_name_parts
    when nil
      [:""]
    else
      # e.g. self::Foo, (var)::Bar = baz
      raise ConstantPathNode::DynamicPartsInConstantPathError, "Constant target path contains dynamic parts. Cannot compute full name"
    end

  if name.nil?
    raise ConstantPathNode::MissingNodesInConstantPathError, "Constant target path contains missing nodes. Cannot compute full name"
  end

  parts.push(name)
end