Bird
0
0

Which of the following is the correct syntax to include a module named Greetings inside a class Person?

easy📝 Syntax Q12 of 15
Ruby - Modules and Mixins
Which of the following is the correct syntax to include a module named Greetings inside a class Person?
Aclass Person; include Greetings; end
Bclass Person; extend Greetings; end
Cclass Person; include(Greetings); end
Dclass Person; use Greetings; end
Step-by-Step Solution
Solution:
  1. Step 1: Recall correct syntax for including modules

    In Ruby, to add instance methods from a module, use include ModuleName inside the class body without parentheses.
  2. Step 2: Check each option

    class Person; include Greetings; end uses include Greetings correctly. class Person; extend Greetings; end uses extend which adds class methods, not instance methods. class Person; include(Greetings); end uses parentheses which is not standard syntax. class Person; use Greetings; end uses use which is invalid in Ruby.
  3. Final Answer:

    class Person; include Greetings; end -> Option A
  4. Quick Check:

    Include syntax = include ModuleName [OK]
Quick Trick: Use 'include ModuleName' without parentheses [OK]
Common Mistakes:
  • Using extend instead of include
  • Adding parentheses after include
  • Using invalid keywords like 'use'

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes