Sha256: e5d81786d486103b1a3b0f696460957067ef506dfaddf5fded81ac167dc1ef16
Contents?: true
Size: 817 Bytes
Versions: 1
Compression:
Stored size: 817 Bytes
Contents
require_relative '../lib/method_observer' class Dummy def foo puts 'Running foo' bar end def bar puts 'Running bar' end end class Profiler def initialize @nesting_level = 0 end def track(klass, target, method, *args, &block) @nesting_level += 1 nesting = ' ' * (@nesting_level - 1) puts "#{nesting}Before: #{klass}#{target == :class ? '.' : '#'}#{method}" result = block.call puts "#{nesting}After: #{klass}#{target == :class ? '.' : '#'}#{method}" @nesting_level -= 1 result end end MethodObserver.configure do |config| profiler = Profiler.new config.around do |klass, target, method, *args, &block| profiler.track klass, target, method, *args, &block end config.observe Dummy, instance: [:foo, :bar] end dummy = Dummy.new dummy.foo
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
method_observer-0.0.1 | examples/nesting.rb |