Extends the given modules to the classes that subsequently include the invoking module or one of its submodules.
Calling SomeMixin.class_extend(SomeClassMethods) would be equivalent to:
module SomeMixin
class_mixin do
include SomeClassMethods
end
end
[ show source ]
# File lib/mixin.rb, line 42
42: def class_extend(*modules)
43: class_mixin { include *modules }
44: end
Works like class_extend except that the given modules are instead extended to the invoking module and the modules that subsequently include it rather than their including classes.
[ show source ]
# File lib/mixin.rb, line 50
50: def module_extend(*modules)
51: module_mixin { include *modules }
52: end
Returns the invoking modules‘s class_mixin module object. When a block is passed, it is evaluated in the context of the class_mixin module.
Given the module M, M‘s class_mixin module is included by the class_mixin module of any module that includes M and is extended to any class that includes M.
module Active
class_mixin do
def active?; true; end
end
end
module Hyper
include Active
class_mixin do
def hyper?; true; end
end
end
class HyperClass
include Hyper
end
HyperClass.active? -> true
HyperClass.hyper? -> true
[ show source ]
# File lib/mixin.rb, line 88
88: def class_mixin(&block) # :doc:
89: __class_mixin__.module_eval(&block) if block_given?
90: __class_mixin__
91: end
Works the same as class_mixin except that the invoking module‘s module_mixin is instead extended to the invoking module itself rather than its including classes.
module Active
module_mixin do
def active_mixin?; true; end
end
end
module Hyper
include Active
end
class ActiveClass
include Active
end
Active.active_mixin? -> true
Hyper.active_mixin? -> true
ActiveClass.respond_to?(:active_mixin?) -> false
[ show source ]
# File lib/mixin.rb, line 120
120: def module_mixin(&block) # :doc:
121: __module_mixin__.module_eval(&block) if block_given?
122: __module_mixin__
123: end