Skip to content

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

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 #class_eval #attr_writer #class_exec also in 4.1 · 4.0 · 3.4 · 3.2 · 3.1 · 3.0