Namespacing with modules
📖 Scenario: Imagine you are organizing a small library system. You want to keep book-related and author-related code separate but still inside the same program. This helps avoid confusion when different parts have similar names.
🎯 Goal: You will create two modules named Books and Authors. Each module will have a class with the same name Info but with different details. Then you will print information from both classes to see how modules keep them separate.
📋 What You'll Learn
Create a module called
Books with a class Info inside itCreate a module called
Authors with a class Info inside itEach
Info class should have a method details that returns a stringUse the full namespaced class names to create objects and call
detailsPrint the results from both
Books::Info and Authors::Info💡 Why This Matters
🌍 Real World
Namespacing with modules is useful when building large programs or libraries where different parts might have classes or methods with the same names.
💼 Career
Understanding modules and namespacing is important for writing clean, maintainable Ruby code and working on team projects or open-source libraries.
Progress0 / 4 steps