Guest User

Untitled

a guest
Feb 19th, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 KB | None | 0 0
  1. # Instrumentation
  2.  
  3. class Controller
  4.  
  5. def dispatch
  6. puts :dispatched
  7. end
  8.  
  9. end
  10.  
  11. class OtherController < Controller
  12. end
  13.  
  14.  
  15. module Timing
  16.  
  17. def dispatch
  18. start = Time.now
  19. super
  20. elapsed = Time.now - start
  21. puts "#{self.class}#dispatch took #{elapsed}s"
  22. end
  23.  
  24. end
  25.  
  26.  
  27. module TimingExtension
  28.  
  29. def new(*args, &block)
  30. super.extend(Timing)
  31. end
  32.  
  33. end
  34.  
  35.  
  36. Controller.extend(TimingExtension)
  37.  
  38. # Runtime
  39.  
  40. Controller.new.dispatch
  41. OtherController.new.dispatch
Add Comment
Please, Sign In to add comment