$30 off During Our Annual Pro Sale. View Details »

Ruby's require, autoload and load methods

DonSchado
January 15, 2014

Ruby's require, autoload and load methods

Autoload is a nice feature, but it's good to know the difference when you begin using multiple files in your projects.

DonSchado

January 15, 2014
Tweet

More Decks by DonSchado

Other Decks in Programming

Transcript

  1. require
    autoload
    load
    @donschado | 15.01.2014

    View Slide

  2. http://ruby-doc.org/core-2.1.0/Kernel.html#method-i-require

    View Slide

  3. View Slide

  4. View Slide

  5. http://ruby-doc.org/core-2.1.0/Kernel.html#method-i-autoload

    View Slide

  6. View Slide

  7. http://ruby-doc.org/core-2.1.0/Kernel.html#method-i-auto

    View Slide

  8. View Slide

  9. View Slide

  10. Matz (2011) "discourage the use of autoload"
    [...] autoload itself has fundamental flaw under
    multi-thread environment. I should have remove
    autoload when I added threads to the language.

    !
    [...] I hereby declare the future deprecation of
    autoload. Ruby will keep autoload for a while,
    since 2.0 should keep compatibility to 1.9.

    But you don't expect it will survive further future,
    e.g. 3.0.

    I strongly discourage the use of autoload in any
    standard libraries.

    https://bugs.ruby-lang.org/issues/5653
    https://www.ruby-forum.com/topic/3036681

    View Slide

  11. ”Peter Cooper: I'll be taking the "cross that bridge
    when I get to it" approach
    What I think after some research...
    http://www.rubyinside.com/ruby-techniques-revealed-autoload-1652.html
    I‘m full of autoload 

    because the lazy loading feature is awesome...

    View Slide