Module: T::Types::Simple::NamePatch

Included in:
T::Types::Simple
Defined in:
lib/tapioca/sorbet_ext/name_patch.rb

Constant Summary collapse

NAME_METHOD =
T.let(Module.instance_method(:name), UnboundMethod)

Instance Method Summary collapse

Instance Method Details

#nameObject



10
11
12
13
14
# File 'lib/tapioca/sorbet_ext/name_patch.rb', line 10

def name
  # Sorbet memoizes this method into the `@name` instance variable but
  # doing so means that types get memoized before this patch is applied
  qualified_name_of(@raw_type)
end

#qualified_name_of(constant) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/tapioca/sorbet_ext/name_patch.rb', line 16

def qualified_name_of(constant)
  name = NAME_METHOD.bind_call(constant)
  name = nil if name&.start_with?("#<")
  return if name.nil?

  if name.start_with?("::")
    name
  else
    "::#{name}"
  end
end