module RKit::Override::Base::Nodef

Public Class Methods

__nodef__(method_name) click to toggle source
# 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