Bird
0
0

How can you fix this code to allow calling Greetings.say_hello?

hard📝 Application Q9 of 15
Ruby - Modules and Mixins
How can you fix this code to allow calling Greetings.say_hello?
module Greetings
  def say_hello
    "Hello!"
  end
end
AAdd self. prefix to method: def self.say_hello
BInclude module in a class before calling
CChange module to class
DCall method with instance of module
Step-by-Step Solution
Solution:
  1. Step 1: Understand method type

    The method say_hello is an instance method, so it cannot be called on the module directly.
  2. Step 2: Make method a module method

    Adding self. prefix makes it callable on the module itself.
  3. Final Answer:

    Add self. prefix to method: def self.say_hello -> Option A
  4. Quick Check:

    Module methods need self. prefix for direct calls [OK]
Quick Trick: Prefix method with self. to call it on module directly [OK]
Common Mistakes:
  • Trying to call instance method on module
  • Changing module to class unnecessarily
  • Calling method on module instance which is invalid

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes