Skip to content

Maintenance Ruby 3.3 gets fixes, but no new features. Switch to Ruby 4.0 →

instance method

Module#autoload

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_.

   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.

See also #autoload? #attr_writer #attr_reader #class_eval also in 4.1 · 4.0 · 3.4 · 3.2 · 3.1 · 3.0