Module: Dizby::PolymorphicDelegated::ClassMethods

Includes:
ClassicAttributeAccess
Defined in:
lib/dizby/utility/polymorphic_delegated.rb

Instance Method Summary collapse

Methods included from ClassicAttributeAccess

#attr_accessor, #attr_reader, #attr_writer

Instance Method Details

#__create_delegated_method__(name)


25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/dizby/utility/polymorphic_delegated.rb', line 25

def __create_delegated_method__(name)
  method = instance_method(name)

  Dizby.redefine_method(self, name) do |*args, &block|
    delegator =
      if args.empty? || !args.first.is_a?(Delegator)
        self
      else
        args.shift
      end

    bound = Dizby.force_bind(delegator, method)
    bound.call(*args, &block)
  end
end

#method_added(name)


41
42
43
44
45
46
# File 'lib/dizby/utility/polymorphic_delegated.rb', line 41

def method_added(name)
  return if %i(method_missing initialize).include?(name)
  return if Dizby.caller == 'redefine_method'

  __create_delegated_method__(name)
end