Bird
0
0

Identify the error in the following Ruby module declaration:

medium📝 Debug Q14 of 15
Ruby - Modules and Mixins
Identify the error in the following Ruby module declaration:
module Tools
  def help
    "Help message"
  end
end

Tools.help
ANo error, code runs fine
BMissing 'end' keyword for module
CMethod 'help' should be defined with 'self.' to call on module
DModule name should be lowercase
Step-by-Step Solution
Solution:
  1. Step 1: Check method definition inside module

    The method help is defined as an instance method, but called on the module directly.
  2. Step 2: Understand method call context

    To call Tools.help, help must be a module method defined with self.help.
  3. Final Answer:

    Method 'help' should be defined with 'self.' to call on module -> Option C
  4. Quick Check:

    Module methods need 'self.' prefix to be called on module [OK]
Quick Trick: Use 'def self.method' for module-level methods [OK]
Common Mistakes:
  • Defining instance methods but calling on module
  • Forgetting 'self.' prefix for module methods
  • Assuming lowercase module names are valid

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes