Recall & Review
beginner
What is the main purpose of using modules for namespacing in Ruby?
Modules group related classes, methods, or constants to avoid name conflicts and organize code clearly.
Click to reveal answer
beginner
How do you define a module named
MathTools in Ruby?Use
module MathTools
# code here
end to define the module.Click to reveal answer
beginner
How do you access a class
Calculator inside a module MathTools?Use the scope resolution operator:
MathTools::Calculator.Click to reveal answer
intermediate
What happens if two classes have the same name but are in different modules?
They are treated as different classes because the module names keep them separate, avoiding conflicts.
Click to reveal answer
intermediate
Can modules be nested inside other modules in Ruby? Why would you do this?
Yes, nesting modules helps organize code hierarchically and create more specific namespaces.
Click to reveal answer
Which symbol is used to access a class inside a module in Ruby?
✗ Incorrect
The scope resolution operator
:: is used to access classes or constants inside modules.What keyword starts the definition of a module in Ruby?
✗ Incorrect
The
module keyword is used to define a module.Why use modules for namespacing?
✗ Incorrect
Modules help avoid name clashes by grouping related code under a unique namespace.
If you have
module A; class B; end; end, how do you create an instance of class B?✗ Incorrect
Use
A::B.new to create an instance of class B inside module A.Can modules contain methods in Ruby?
✗ Incorrect
Modules can contain methods, which can be used as mixins or namespaced functions.
Explain how modules help prevent name conflicts in Ruby programs.
Think about how two classes with the same name can exist without problems.
You got /4 concepts.
Describe how to define and use a class inside a nested module structure.
Imagine folders inside folders to organize files.
You got /4 concepts.