Complete the code to define a module with an included hook method.
module Greetings def self.[1](base) puts "Module included in #{base}" end end
The included method is a special hook in Ruby modules that runs when the module is included in another class or module.
Complete the code to include the module and trigger the included hook.
class Person [1] Greetings end
The include keyword adds the module's methods as instance methods to the class and triggers the included hook.
Fix the error in the included hook method definition.
module Logger def self.included(base) base.[1] LoggerMethods end end
Inside the included hook, calling base.extend LoggerMethods adds methods as class methods to the including class.
Fill both blanks to define a module with an included hook that adds class methods.
module Trackable def self.[1](base) base.[2] ClassMethods end module ClassMethods def track puts "Tracking enabled" end end end
The included hook is used to call extend on the base class to add class methods from the nested module.
Fill all three blanks to create a module with an included hook that adds instance and class methods.
module Auditable def self.[1](base) base.[2] InstanceMethods base.[3] ClassMethods end module InstanceMethods def audit puts "Instance audit" end end module ClassMethods def audit puts "Class audit" end end end
extend for instance methods or include for class methods.The included hook calls include to add instance methods and extend to add class methods to the base.