Module: SimpleDebugLogging::InstanceMethodLoggerModulizer

Defined in:
lib/simple_debug_logging.rb

Class Method Summary collapse

Class Method Details

.to_mod(methods_to_log = []) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/simple_debug_logging.rb', line 37

def self.to_mod(methods_to_log = [])
  Module.new do
    Array(methods_to_log).each do |method_to_log|
      define_method(method_to_log.to_sym) do |*args, &block|
        method_return_value = nil
        invocation_id = " ~#{args.object_id}@#{Time.now.to_i}~" if args
        puts "#{self.class}##{method_to_log}(#{args.map {|x| x.inspect}.join(", ")})#{invocation_id}"
        elapsed = Benchmark.realtime do
          method_return_value = super(*args, &block)
        end
        puts "#{self.class}##{method_to_log} ~#{args.hash}~ complete in #{elapsed}s#{invocation_id}"
        method_return_value
      end
    end
  end
end