Last active
August 29, 2015 13:56
-
-
Save mje113/9190455 to your computer and use it in GitHub Desktop.
Ruby 2.1 method injection POC
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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