Module: InstanceMethodWrapper
Class Method Summary collapse
Methods included from ImwUx
Class Method Details
.prepended(base) ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/instance_method_wrapper.rb', line 69 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 |
.wrap_method(base, method_name) ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/instance_method_wrapper.rb', line 84 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 |