A library of utility services and concerns.
Implements recursive inheritance of both class and instance methods.
Defining A Mixin
module Widgets
extend SleepingKingStudios::Tools::Toolbox::Mixin
module ClassMethods
def widget_types
%w(gadget doohickey thingamabob)
end
end
def widget?(widget_type)
self.class.widget_types.include?(widget_type)
end
end
Including A Mixin
module WidgetBuilding
extend SleepingKingStudios::Tools::Toolbox::Mixin
include Widgets
def build_widget(widget_type)
raise ArgumentError, 'not a widget', caller unless widget?(widget_type)
Widget.new(widget_type)
end
end
Using A Mixin
class WidgetFactory
include WidgetBuilding
end
factory = WidgetFactory.new
factory.build_widget('gadget')
#=> Widget
WidgetFactory.widget_types
#=> ['gadget', 'doohickey', 'thingamabob']
.mixin?(othermod) => true, false
Checks if the given module is itself a Mixin.
#included(othermod) => void
Callback invoked whenever the receiver is included in another module.
#prepended(othermod) => void
Callback invoked whenever the receiver is prepended into another module.
Back to Documentation | Reference | SleepingKingStudios | SleepingKingStudios::Tools | SleepingKingStudios::Tools::Toolbox