Module: SleepingKingStudios::Tools::Toolbox::Mixin

Defined in:
lib/sleeping_king_studios/tools/toolbox/mixin.rb

Overview

Implements recursive inheritance of both class and instance methods.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.mixin?(mod) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


9
10
11
12
13
# 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

Instance Method Details

#included(other) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# 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