Bird
0
0

Find the error in this code:

medium📝 Debug Q6 of 15
Ruby - Modules and Mixins
Find the error in this code:
module Tools
  class Hammer
    def hit
      puts 'Bang'
    end
  end
end

puts Tools.Hammer.new.hit
AMissing end keyword for module
BUsing dot (.) instead of :: to access Hammer
CMethod hit should be a class method
DCannot call puts inside method
Step-by-Step Solution
Solution:
  1. Step 1: Check module and class access syntax

    Ruby requires :: to access classes inside modules, not dot (.).
  2. Step 2: Identify the incorrect usage

    The code uses Tools.Hammer which is invalid syntax.
  3. Final Answer:

    Using dot (.) instead of :: to access Hammer -> Option B
  4. Quick Check:

    Access module class with :: not . [OK]
Quick Trick: Use :: not . to access module contents [OK]
Common Mistakes:
  • Using dot instead of ::
  • Forgetting end keyword
  • Confusing instance and class methods

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes