Module: Dizby::PolymorphicDelegated

Included in:
TCProtocol::Server, UnixProtocol::Server
Defined in:
lib/dizby/utility/polymorphic_delegated.rb

Defined Under Namespace

Modules: ClassMethods, InstanceMethods

Class Method Summary collapse

Class Method Details

.included(base)


10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/dizby/utility/polymorphic_delegated.rb', line 10

def self.included(base)
  base.extend(ClassMethods)
  base.__send__(:include, InstanceMethods)

  base.class_eval do
    intercepted = [base, Object, Kernel, BasicObject, InstanceMethods]
    intercepted = intercepted.map(&:instance_methods).reduce(&:-)

    @__delegated_methods__ =
      intercepted.each_with_object({}) do |name, methods|
        methods[name.to_sym] = base.instance_method(name)
        base.__send__(:undef_method, name)
      end
  end
end