-
Notifications
You must be signed in to change notification settings - Fork 4
Limitations and Caveats
-
SuperModule has been designed to be used only in the code definition of a module, not to be mixed in at run-time.
-
Initial Ruby runtime load of a class or module mixing in SuperModule will incur a very marginal performance hit (in the order of nano-to-milliseconds). However, class usage (instantiation and method invocation) will not incur any performance hit, running as fast as any other Ruby class.
-
Given SuperModule's implementation relies on
self.included(base)
, if an including super module (or a super module including another super module) must hook intoself.included(base)
for meta-programming cases that require it, such as conditionalinclude
statements or method definitions, it would have to aliasself.included(base)
and then invoke the aliased version in every super module that needs it like in this example:
module AdminIdentifiable
include SuperModule
include UserIdentifiable
class << self
alias included_super_module included
def included(base)
included_super_module(base)
# do some extra work
# like conditional inclusion of other modules
# or conditional definition of methods
end
end
In the future, SuperModule could perhaps provide robust built-in facilities for allowing super modules to easily hook into self.included(base)
without interfering with SuperModule behavior.
- Only public singleton methods are copied by SuperModule to an including class (or module)