Skip to content

Instantly share code, notes, and snippets.

@mje113
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mje113/9190455 to your computer and use it in GitHub Desktop.
Save mje113/9190455 to your computer and use it in GitHub Desktop.
Ruby 2.1 method injection POC
module Instrumenter
def instrument(method)
alias_method "_#{method}", method
define_method method do
start = Time.now
result = send("_#{method}")
puts "Elapsed: #{Time.now - start}"
result
end
end
end
class Calculator
extend Instrumenter
instrument def calculate
sleep 1
1 + 1
end
end
i = Calculator.new
puts i.calculate
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment