module SleepingKingStudios::Tools::Toolbox::Mixin

Implements recursive inheritance of both class and instance methods.

Public Class Methods

mixin?(mod) click to toggle source

@api private

# File lib/sleeping_king_studios/tools/toolbox/mixin.rb, line 9
def self.mixin?(mod)
  return false unless mod.is_a?(Module)

  mod.singleton_class.include?(self)
end

Public Instance Methods

included(other) click to toggle source

@private

Calls superclass method
# File lib/sleeping_king_studios/tools/toolbox/mixin.rb, line 16
def included(other)
  return super unless defined?(self::ClassMethods)

  if SleepingKingStudios::Tools::Toolbox::Mixin.mixin?(other)
    unless other.constants(false).include?(:ClassMethods)
      other.const_set(:ClassMethods, Module.new)
    end

    other::ClassMethods.include(self::ClassMethods)
  else
    other.extend self::ClassMethods
  end

  super
end