Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Zeitwerk integration in Rails 6.0

Zeitwerk integration in Rails 6.0

My speak slide at The 88th RubyKansai.

murajun1978

December 07, 2019
Tweet

More Decks by murajun1978

Other Decks in Programming

Transcript

  1. Zeitwerk integration
    in Rails 6.0
    The 88th RubyKansai

    View full-size slide

  2. self.inspect
    {
    name: “@murajun1978”,
    nickname: “むらじゅん”,
    avatar: ,
    job: “Web Developer”,
    interested: [“Ruby”,”Rails”,”React”,”TypeScript”,”GraphQL”,”Serverless”],
    communities: [“Shinosaka.rb”,”Rails Follow-up Osaka”,...],
    }

    View full-size slide

  3. Agenda
    ● Zeitwerk integration in Rails 6.0
    ● What is Zeitwerk?
    ● Why use Zeitwerk?
    ● How use Zeitwerk?
    ● Conclusion

    View full-size slide

  4. Zeitwerk integration in Rails 6.0

    View full-size slide

  5. Zeitwerk is default (Rails >= v6.0)
    rails/railties/lib/rails/application/configuration.rb

    View full-size slide

  6. You can use classic loader
    https://guides.rubyonrails.org/autoloading_and_reloading_constants.html#opting-out

    View full-size slide

  7. But deprecation    

    View full-size slide

  8. Load code at startup with Zeitwerk
    rails/railties/lib/rails/application/finisher.rb

    View full-size slide

  9. What is Zeitwerk?

    View full-size slide

  10. Zeitwerk
    ● Gem (https://github.com/fxn/zeitwerk)
    ● Zeitwerk is an efficient and thread-safe code loader for Ruby
    ● You can load modules with autoloading or eager loading
    ● Without ‘require’
    ● You can also reload modules
    ● Using Kernel.#autoload
    ● Implicit namespaces
    ● Explicit namespaces
    ● Nested root directories

    View full-size slide

  11. No dependencies!!!
    zeitwerk/zeitwerk.gemspec

    View full-size slide

  12. Pure Ruby   

    View full-size slide

  13. Why use Zeitwerk?

    View full-size slide

  14. Zeitwerk (Pros)
    ● Efficient and thread-safe
    ● You can load modules with autoloading or eager loading
    ● Without ‘require’
    ● You can also reload modules
    ● Using Kernel.#autoload
    ● Implicit namespaces
    ● Explicit namespaces
    ● Nested root directories
    ● No dependencies

    View full-size slide

  15. Zeitwerk (Cons)
    ● ...

    View full-size slide

  16. How use Zeitwerk?

    View full-size slide

  17. That’s it  

    View full-size slide

  18. Implicit namespaces

    View full-size slide

  19. Explicit namespaces

    View full-size slide

  20. Conclusion
    ● Zeitwerk is Cool !!!
    ● Zeitwerk integration in Rails 6.0
    ● You can build library without ‘require’
    ● You can use it easily

    View full-size slide

  21. Enjoy Ruby with Zeitwerk  

    View full-size slide

  22. Thanks  

    View full-size slide