Homepage / Report Issue / Source Code ( Build Status )

Autoload

Offical word has it autoload is dead.

But like James Brown, "Autoload is alive!"

Instructions

It works just like the good old autoload we have always loved.

Let's say we have a dependency on a library called "splinter", but it is only used in special cases, so it would be good to only load it when needed.

  autoload :Splinter, 'splinter'

Now, as soon as we try to access the Splinter constant the splinter library will be loaded.

  Splinter

Autoload can be used relative to existing namespaces as well. For instance, Bundler uses it to load it's own scripts.

  module Bundler
    # ...
    autoload :Definition, 'bundler/definition'
    autoload :Dependency, 'bundler/dependency'
    autoload :DepProxy, 'bundler/dep_proxy'
    autoload :Deprecate, 'bundler/deprecate'
    autoload :Dsl, 'bundler/dsl'
    # ...
  end

Limitations

  • Autoload is not thread safe. You need thread safe autoload? Submit a patch, please.

Copyrights

Autoload is copyrighted open-source software.

Copyright (c) 2013 Rubyworks

It can be modified and redistributed in accordance with the BSD-2-Clause license.

See LICENSE.txt for license details.