module InstanceMethodWrapper
def self.prepended(base)
def self.prepended(base) base.instance_methods(false).each do |method_name| wrap_method(base, method_name) unless %i[method_missing].include? method_name end base.singleton_class.send(:define_method, :method_added) do |method_name| unless @_currently_adding_method @_currently_adding_method = true InstanceMethodWrapper.wrap_method(self, method_name) @_currently_adding_method = false end end end
def self.wrap_method(base, method_name)
def self.wrap_method(base, method_name) sbase = base.to_s.gsub(/[a-z]/, '') original_method = base.instance_method(method_name) base.send(:define_method, method_name) do |*args, **kwargs, &block| warn format("%s %.#{$imw_len}s", imw_indent(:in).to_s, "#{sbase}::#{method_name}: " + [args == [] ? nil : "args=#{args.inspect}", kwargs == {} ? nil : "kwargs=#{kwargs.inspect}"].compact.join(', ')) $imw_depth += 1 original_method.bind(self).call(*args, **kwargs, &block).tap do |result| ### if !%w[method_missing].include? method_name $imw_depth -= 1 warn format("%s %.#{$imw_len}s", imw_indent(:out).to_s, "#{sbase}::#{method_name}: " + result.inspect) # end end end end