Module: RKit::Override::Base::Nodef

Defined in:
lib/r_kit/override/base.rb

Class Method Summary collapse

Class Method Details

.__nodef__(method_name) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/r_kit/override/base.rb', line 25

def self.__nodef__ method_name
  define_method :__olddef__ do |*args, &block|

    if respond_to?(:__getobj__) && __getobj__.respond_to?(method_name)
      __getobj__.send(method_name, *args, &block)

    else
      owner = self.class.instance_method(method_name).owner
      __newdef__ = owner.instance_method(method_name)
      owner.send :remove_method, method_name

      closure = if respond_to?(method_name)
        send(method_name, *args, &block)
      end

      owner.send(:define_method, method_name, __newdef__)
      closure
    end
  end

  instance_method :__olddef__
end