Recall & Review
beginner
What does the
include keyword do in Ruby?It adds the methods from a module as instance methods to a class, so objects of that class can use those methods.Click to reveal answer
beginner
How do instance methods from a module become available in a Ruby class?
By using
include ModuleName inside the class, the module's instance methods become instance methods of the class.Click to reveal answer
beginner
Given this module:<br>
module Greet
def hello
"Hi!"
end
end<br>How do you make hello available to instances of class Person?Inside the
Person class, write include Greet. Then any Person object can call hello.Click to reveal answer
intermediate
What is the difference between
include and extend in Ruby?<code>include</code> adds module methods as instance methods. <code>extend</code> adds them as class methods.Click to reveal answer
beginner
Can a Ruby class include multiple modules for instance methods?Yes, a class can include many modules. All their instance methods become available to the class's objects.Click to reveal answer
What happens when you use
include with a module in a Ruby class?✗ Incorrect
Using
include adds the module's methods as instance methods to the class.Which keyword adds module methods as class methods instead of instance methods?
✗ Incorrect
extend adds module methods as class methods.If a module has a method
greet, how do you call it on an object of a class that included the module?✗ Incorrect
Instance methods from included modules are called on objects.
Can a Ruby class include more than one module to get instance methods?
✗ Incorrect
Ruby classes can include many modules to get their instance methods.
What is the effect of including a module inside a Ruby class?
✗ Incorrect
Including a module adds its instance methods to the class.
Explain how the
include keyword works to add instance methods from a module to a Ruby class.Think about how a class gets new methods from a module.
You got /4 concepts.
Describe the difference between
include and extend when using modules in Ruby.One affects objects, the other affects the class itself.
You got /3 concepts.