Complete the code to include the module as a mixin in the class.
module Greetings def greet "Hello!" end end class Person [1] Greetings end
Use include to mix in a module's instance methods into a class.
Complete the code to call the mixin method from an instance.
module Logger def log(message) "Log: #{message}" end end class App include Logger end app = App.new puts app.[1]("Started")
The method log is defined in the module and mixed in as an instance method, so call app.log.
Fix the error by choosing the correct keyword to add module methods as class methods.
module Tools def info "Tool info" end def details "Details" end end class Machine [1] Tools end puts Machine.info
Use extend to add module methods as class methods.
Fill both blanks to create a mixin module and include it in a class.
module [1] def shout "Hey!" end end class [2] include Shoutable end
The module name must match the one included in the class. The class name can be any valid name.
Fill all three blanks to define a module with an instance method, include it in a class, and call the method.
module [1] def greet "Hi!" end end class [2] [3] Greetings end obj = Greeter.new puts obj.greet
The module is named 'Greetings', the class 'Greeter' includes it with 'include', then the instance calls the method.