class Carbon::Concrete::Type::Name
The “name” of a type. This contains all of the physical information of a type. This mostly means the “parts” for the name, and the function information if it is included.
@note
**This class is frozen upon initialization.** This means that any attempt to modify it will result in an error. In most cases, the attributes on this class will also be frozen, as well.
Attributes
The function information of a type. If no function information was included (i.e. the type is a module), then this is `nil`. Function
information always includes a name and the parameters, if it is included.
@api public @example
full = "Carbon::Pointer<T>.+(Carbon::Pointer<T>, Carbon::Int32)" type = Carbon::Type(full) name = type.name name.function.to_s # => "+(Carbon::Pointer<T>, Carbon::Int32)"
@return [Type::Function] The function information.
The parts of the name. This is mainly the sections of the type name; for example, for `Carbon::Pointer`, the parts are `Carbon` and `Pointer`. Each part can contain generic information; however, by convention, only the last part is actually included for generic information.
@api semipublic @example
type = Carbon::Type("Carbon::Pointer<T>") name = type.name name.parts # => [#<Carbon::Concrete::Type::Part Carbon>, # #<Carbon::Concrete::Type::Part Pointer>]
@return [<Type::Part>] The parts.
Public Class Methods
Initialize the name with the given parts and function information. Freezes the class after completion.
@param parts [<Type::Part>] The parts of the name. @param function [Type::Function?] The function part of the name, if
it exists.
# File lib/carbon/concrete/type/name.rb, line 100 def initialize(parts, function) @parts = parts.freeze @function = function to_s intern deep_freeze! end
Public Instance Methods
An interned name of the type. Unlike {#to_s}, this doesn't include any generic information.
@api public @example
type = Carbon::Type("Carbon::Pointer<T>") type.intern # => "Carbon::Pointer"
@note See {Item::Base#intern} For more information about interned
names.
@return [::String] The interned name of the type.
# File lib/carbon/concrete/type/name.rb, line 136 def intern @_intern ||= if @function "#{@parts.map(&:intern).join('::')}.#{@function.intern}" else @parts.map(&:intern).join("::") end.freeze end
A string representation of the name. Unlike {#intern}, this includes all generic information as well.
@api public @example
type = Carbon::Type("Carbon::Pointer<T>") type.to_s # => "Carbon::Pointer<T>"
@return [::String] The string representation.
# File lib/carbon/concrete/type/name.rb, line 117 def to_s @_to_s ||= if @function "#{@parts.map(&:to_s).join('::')}.#{@function}" else @parts.map(&:to_s).join("::") end.freeze end