Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →
instance method
Module#autoload?
(::interned name, ?::boolish inherit) -> ::String?
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
See also
#autoload
#autoload_relative
#attr_writer
#class_eval
also in
4.0 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0