I am a little confused by this example on ActiveSupport::Concern from the documentation:
module M
def self.included(base)
base.extend ClassMethods
base.class_eval do
scope :disabled, -> { where(disabled: true) }
end
end
module ClassMethods
...
end
end
self.included in a Module is called when you include or extend the Module in a Class. base refers to the object, whether it is a class object or object instance. extend on base will include the methods in Module as singleton methods on base. include will add the methods to the class object's instances.
However, class_eval also is used to add instance methods to a class object's instances. Yet, scope is a class method:
Adds a class method for retrieving and querying objects.
Since scope is a class method, why is the example using class_eval rather than instance_eval?