module ActiveSupport::Dependencies::Loadable

Public Instance Methods

require_dependency(file_name, message = "No such file to load -- %s.rb") Show source
# File activesupport/lib/active_support/dependencies.rb, line 282
def require_dependency(file_name, message = "No such file to load -- %s.rb")
  file_name = file_name.to_path if file_name.respond_to?(:to_path)
  unless file_name.is_a?(String)
    raise ArgumentError, "the file name must either be a String or implement #to_path -- you passed #{file_name.inspect}"
  end

  Dependencies.depend_on(file_name, message)
end

Warning: This method is obsolete in :zeitwerk mode. In :zeitwerk mode semantics match Ruby's and you do not need to be defensive with load order. Just refer to classes and modules normally. If the constant name is dynamic, camelize if needed, and constantize.

In :classic mode, interprets a file using mechanism and marks its defined constants as autoloaded. file_name can be either a string or respond to to_path.

In :classic mode, use this method in code that absolutely needs a certain constant to be defined at that point. A typical use case is to make constant name resolution deterministic for constants with the same relative name in different namespaces whose evaluation would depend on load order otherwise.

Engines that do not control the mode in which their parent application runs should call require_dependency where needed in case the runtime mode is :classic.

© 2004–2020 David Heinemeier Hansson
Licensed under the MIT License.