module Kernel

Public Instance Methods

require(path) click to toggle source

@sig (String) -> true | false

# File lib/zeitwerk/kernel.rb, line 24
def require(path)
  if loader = Zeitwerk::Registry.loader_for(path)
    if path.end_with?(".rb")
      required = zeitwerk_original_require(path)
      loader.on_file_autoloaded(path) if required
      required
    else
      loader.on_dir_autoloaded(path)
      true
    end
  else
    required = zeitwerk_original_require(path)
    if required
      abspath = $LOADED_FEATURES.last
      if loader = Zeitwerk::Registry.loader_for(abspath)
        loader.on_file_autoloaded(abspath)
      end
    end
    required
  end
end
Also aliased as: zeitwerk_original_require
zeitwerk_original_require(path)

We are going to decorate Kernel#require with two goals.

First, by intercepting Kernel#require calls, we are able to autovivify modules on required directories, and also do internal housekeeping when managed files are loaded.

On the other hand, if you publish a new version of a gem that is now managed by Zeitwerk, client code can reference directly your classes and modules and should not require anything. But if someone has legacy require calls around, they will work as expected, and in a compatible way. This feature is by now EXPERIMENTAL and UNDOCUMENTED.

We cannot decorate with prepend + super because Kernel has already been included in Object, and changes in ancestors don't get propagated into already existing ancestor chains.

Alias for: require