Skip to content

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

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