class Zeitwerk::Cref
This private class encapsulates pairs (mod, cname).
Objects represent the constant ‘cname` in the class or module object `mod`, and have API to manage them. Examples:
cref.path cref.set(value) cref.get
The constant may or may not exist in ‘mod`.
Attributes
cname[R]
: Symbol
mod[R]
: Module
Public Class Methods
new(mod, cname)
click to toggle source
The type of the first argument is Module because Class < Module, class objects are also valid.
: (Module, Symbol) -> void
# File lib/zeitwerk/cref.rb, line 28 def initialize(mod, cname) @mod = mod @cname = cname @path = nil end
Public Instance Methods
autoload(abspath)
click to toggle source
: (String) -> nil
# File lib/zeitwerk/cref.rb, line 46 def autoload(abspath) @mod.autoload(@cname, abspath) end
autoload?()
click to toggle source
: () -> String?
# File lib/zeitwerk/cref.rb, line 41 def autoload? @mod.autoload?(@cname, false) end
defined?()
click to toggle source
: () -> bool
# File lib/zeitwerk/cref.rb, line 51 def defined? @mod.const_defined?(@cname, false) end
get()
click to toggle source
: () -> top ! NameError
# File lib/zeitwerk/cref.rb, line 61 def get @mod.const_get(@cname, false) end
path()
click to toggle source
: () -> String
# File lib/zeitwerk/cref.rb, line 35 def path @path ||= Object == @mod ? @cname.name : "#{real_mod_name(@mod)}::#{@cname.name}".freeze end
Also aliased as: to_s
remove()
click to toggle source
: () -> void ! NameError
# File lib/zeitwerk/cref.rb, line 66 def remove @mod.__send__(:remove_const, @cname) end
set(value)
click to toggle source
: (top) -> top
# File lib/zeitwerk/cref.rb, line 56 def set(value) @mod.const_set(@cname, value) end