Bird
0
0

Which of the following is the correct way to include a module Flyable into a class Bird in Ruby?

easy📝 Syntax Q12 of 15
Ruby - Modules and Mixins
Which of the following is the correct way to include a module Flyable into a class Bird in Ruby?
Aclass Bird; extend Flyable; end
Bclass Bird; include Flyable; end
Cclass Bird; inherits Flyable; end
Dclass Bird; use Flyable; end
Step-by-Step Solution
Solution:
  1. Step 1: Recall module inclusion syntax

    In Ruby, to add instance methods from a module to a class, you use include ModuleName.
  2. Step 2: Check each option

    class Bird; include Flyable; end uses include Flyable, which is correct. class Bird; inherits Flyable; end uses inherits which is invalid syntax. class Bird; extend Flyable; end uses extend, which adds methods as class methods, not instance methods. class Bird; use Flyable; end uses use, which is not Ruby syntax.
  3. Final Answer:

    class Bird; include Flyable; end -> Option B
  4. Quick Check:

    Use include to add module methods as instance methods = C [OK]
Quick Trick: Use include to add module methods to instances [OK]
Common Mistakes:
  • Using extend instead of include for instance methods
  • Using invalid keywords like inherits or use
  • Confusing class and instance method inclusion

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes