Slide 1

Slide 1 text

Zeitwerk integration in Rails 6.0 The 88th RubyKansai

Slide 2

Slide 2 text

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

Slide 3

Slide 3 text

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

Slide 4

Slide 4 text

Zeitwerk integration in Rails 6.0

Slide 5

Slide 5 text

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

Slide 6

Slide 6 text

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

Slide 7

Slide 7 text

But deprecation    

Slide 8

Slide 8 text

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

Slide 9

Slide 9 text

What is Zeitwerk?

Slide 10

Slide 10 text

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

Slide 11

Slide 11 text

No dependencies!!! zeitwerk/zeitwerk.gemspec

Slide 12

Slide 12 text

Pure Ruby   

Slide 13

Slide 13 text

Why use Zeitwerk?

Slide 14

Slide 14 text

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

Slide 15

Slide 15 text

Zeitwerk (Cons) ● ...

Slide 16

Slide 16 text

How use Zeitwerk?

Slide 17

Slide 17 text

Normally

Slide 18

Slide 18 text

That’s it  

Slide 19

Slide 19 text

Implicit namespaces

Slide 20

Slide 20 text

Explicit namespaces

Slide 21

Slide 21 text

For Gem

Slide 22

Slide 22 text

Demo

Slide 23

Slide 23 text

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

Slide 24

Slide 24 text

Enjoy Ruby with Zeitwerk  

Slide 25

Slide 25 text

Thanks