Maintenance Ruby 3.3 gets fixes, but no new features. Switch to Ruby 4.0 →
instance method
Module#autoload?
mod.autoload?(name, inherit=true) → String or nil
load.c
View on GitHub ↗
static VALUE
rb_mod_autoload_p(int argc, VALUE *argv, VALUE mod)
{
int recur = (rb_check_arity(argc, 1, 2) == 1) ? TRUE : RTEST(argv[1]);
VALUE sym = argv[0];
ID id = rb_check_id(&sym);
if (!id) {
return Qnil;
}
return rb_autoload_at_p(mod, id, recur);
}
Returns filename to be loaded if name is registered as autoload in the namespace of mod or one of its ancestors.
Example
module A end A.autoload(:B, "b") A.autoload?(:B) #=> "b"
If inherit is false, the lookup only checks the autoloads in the receiver:
Example
class A autoload :CONST, "const.rb" end class B < A end B.autoload?(:CONST) #=> "const.rb", found in A (ancestor) B.autoload?(:CONST, false) #=> nil, not found in B itself