Zeitwerk integration in Rails 6.0

Zeitwerk integration in Rails 6.0

My speak slide at The 88th RubyKansai.

D8cd979e90361eb5ca5414dd15b35d0f?s=128

murajun1978

December 07, 2019
Tweet

Transcript

  1. Zeitwerk integration in Rails 6.0 The 88th RubyKansai

  2. self.inspect { name: “@murajun1978”, nickname: “むらじゅん”, avatar: , job: “Web

    Developer”, interested: [“Ruby”,”Rails”,”React”,”TypeScript”,”GraphQL”,”Serverless”], communities: [“Shinosaka.rb”,”Rails Follow-up Osaka”,...], }
  3. Agenda • Zeitwerk integration in Rails 6.0 • What is

    Zeitwerk? • Why use Zeitwerk? • How use Zeitwerk? • Conclusion
  4. Zeitwerk integration in Rails 6.0

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

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

  7. But deprecation    

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

  9. What is Zeitwerk?

  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
  11. No dependencies!!! zeitwerk/zeitwerk.gemspec

  12. Pure Ruby   

  13. Why use Zeitwerk?

  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
  15. Zeitwerk (Cons) • ...

  16. How use Zeitwerk?

  17. Normally

  18. That’s it  

  19. Implicit namespaces

  20. Explicit namespaces

  21. For Gem

  22. Demo

  23. Conclusion • Zeitwerk is Cool !!! • Zeitwerk integration in

    Rails 6.0 • You can build library without ‘require’ • You can use it easily
  24. Enjoy Ruby with Zeitwerk  

  25. Thanks