Bird
0
0

Identify the problem in this code snippet:

medium📝 Debug Q7 of 15
Ruby - Modules and Mixins
Identify the problem in this code snippet:
module Kitchen
  def self.cook
    'Cooking'
  end

  class Oven
  end
end

puts Kitchen::Oven.cook
AOven class does not have method cook
BMissing end for Oven class
Ccook method should be instance method
DCannot call puts on module method
Step-by-Step Solution
Solution:
  1. Step 1: Analyze method location

    cook is a class method of module Kitchen, not of class Oven.
  2. Step 2: Check method call

    Calling Kitchen::Oven.cook fails because Oven has no cook method.
  3. Final Answer:

    Oven class does not have method cook -> Option A
  4. Quick Check:

    Method must be defined in called class/module [OK]
Quick Trick: Methods belong to the class/module they are defined in [OK]
Common Mistakes:
  • Calling method on wrong class
  • Missing class end
  • Confusing instance and class methods

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes