How are modules used as namespaces in Ruby?
Last updated
A
modulewraps classes and constants so their qualified names (e.g.Billing::Invoice) are unique and avoid collisions with other libraries.Code inside the module body sees sibling constants without the prefix.
Namespace modules are never instantiated. They only organize code (being a mixin is a separate role).
- https://thoughtbot.com/blog/why-you-should-nest-modules-in-ruby
- https://docs.ruby-lang.org/en/2.0.0/syntax/modules_and_classes_rdoc.html
- https://blog.appsignal.com/2021/01/13/using-mixins-and-modules-in-your-ruby-on-rails-application.html
- https://dev.to/sonianand11/ruby-interview-questions-part-1-44dp
- https://medium.com/@vincentwilliams0315/modularization-and-namespacing-in-ruby-on-rails-a-guide-for-aspiring-developers-2bf16fa9335e
- https://medium.com/@dnaresh2323/understanding-modules-in-ruby-a-beginners-guide-81fad7e42812
- https://www.geeksforgeeks.org/ruby/namespaces-in-ruby/