class Zeitwerk::Cref

The constant may or may not exist in ‘mod`.
cref.get
cref.set(value)
cref.path
and have API to manage them. Examples:
Objects represent the constant `cname` in the class or module object `mod`,
This private class encapsulates pairs (mod, cname).

def autoload(abspath)

: (String) -> nil
def autoload(abspath)
  @mod.autoload(@cname, abspath)
end

def autoload?

: () -> String?
def autoload?
  @mod.autoload?(@cname, false)
end

def defined?

: () -> bool
def defined?
  @mod.const_defined?(@cname, false)
end

def get

: () -> top ! NameError
def get
  @mod.const_get(@cname, false)
end

def initialize(mod, cname)

: (Module, Symbol) -> void

objects are also valid.
The type of the first argument is Module because Class < Module, class
def initialize(mod, cname)
  @mod   = mod
  @cname = cname
  @path  = nil
end

def path

: () -> String
def path
  @path ||= Object == @mod ? @cname.name : "#{real_mod_name(@mod)}::#{@cname.name}".freeze
end

def remove

: () -> void ! NameError
def remove
  @mod.__send__(:remove_const, @cname)
end

def set(value)

: (top) -> top
def set(value)
  @mod.const_set(@cname, value)
end