Skip to content

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

instance method

Kernel#autoload

(::interned _module, ::String filename) -> ::NilClass
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.

Example
autoload(:MyModule, "/usr/local/lib/modules/my_module.rb")

If const 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? #at_exit #Array #binding also in 4.1 · 4.0 · 3.3 · 3.2 · 3.1 · 3.0