Often, I see stuff like this:
class Someclass
do_something_to :foo, :bar, :class_level
def foo
puts "Hi!"
end
def bar
end
def self.class_level
puts "Something else!"
end
end
I want to patch Class
or Object
to have my own version of do_something_to
. Doesn't need to do anything fancy, a simple printout of the current time vs time at the beginning and end will do.
Here's a solution that works, except that it doesn't address class-level methods:
require 'aspector'
class Class
def do_something_to(*names)
aspector do
around(names) do |proxy, *args, &block|
start_time = Time.now.to_f
proxy.call *args, &block
final_time = Time.now.to_f - start_time
puts final_time
return final_time
end
end
end
end
class MyClass
do_something_to :hey, :derp
def hey
puts "Hey!"
sleep 1
end
def derp x
puts x
sleep 2
end
end