Module declaration syntax
📖 Scenario: You are organizing a small Ruby program that groups related methods inside a module. This helps keep your code neat and reusable.
🎯 Goal: Create a Ruby module named MathHelpers that contains a method to add two numbers.
📋 What You'll Learn
Create a module named
MathHelpersInside the module, define a method called
add that takes two parameters a and bThe
add method should return the sum of a and bCall the
add method from the MathHelpers module with arguments 5 and 7Print the result of the method call
💡 Why This Matters
🌍 Real World
Modules are used in Ruby to group related methods and constants, making code easier to maintain and reuse.
💼 Career
Understanding modules is important for Ruby developers to organize code and use libraries effectively.
Progress0 / 4 steps