Maintenance Ruby 3.4 gets fixes, but no new features. Switch to Ruby 4.0 →
instance method
Module#autoload
(::interned _module, ::String filename) -> ::NilClass
mod.autoload(const, filename) → nil
load.c
View on GitHub ↗
static VALUE
rb_mod_autoload(VALUE mod, VALUE sym, VALUE file)
{
ID id = rb_to_id(sym);
FilePathValue(file);
rb_autoload_str(mod, id, file);
return Qnil;
}
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.