Skip to content

Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →

instance method

Module#autoload

(::interned constant, ::path filename) -> nil
mod.autoload(const, filename) → nil

Registers filename to be loaded (using Kernel::require) the first time that const (which may be a String or a symbol) is accessed in the namespace of mod.

Example
module A
end
A.autoload(:B, "b")
A::B.doit            # autoloads "b"

If const in mod is defined as autoload, the file name to be loaded is replaced with filename. If const is defined but not as autoload, does nothing.

Files that are currently being loaded must not be registered for autoload.