3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/benchmarked/class_methods.rb', line 3
def handle_with_benchmark(method_name)
aliased_method_name = method_name.to_s.sub(/([?!=])$/, '')
punctuation = $1
with = "#{aliased_method_name}_with_benchmark#{punctuation}"
without = "#{aliased_method_name}_without_benchmark#{punctuation}"
define_method(with) do |*args, &block|
ret = nil
Benchmarked.benchmark_and_notify(self, method_name, args) do
ret = send(without, *args, &block)
end
ret
end
alias_method without, method_name
alias_method method_name, with
if public_method_defined?(without)
public with, method_name
elsif protected_method_defined?(without)
protected with, method_name
elsif private_method_defined?(without)
private with, method_name
end
end
|