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
|
# File 'lib/utils/method_debugger.rb', line 3
def self.included(sub_klass)
sub_klass.class_eval do
@@__debug_log = []
@@__method_table = Hash.new{|hash, key| hash[key] = {}}
def self.method_added(method_name)
return if @@__method_table[self][method_name]
@@__method_table[self][method_name] = true
return if method_name.to_s.match(/^__/)
alias_method "__#{method_name}".to_sym, method_name
self_class = self
define_method(method_name) do |*method_args, &block|
caller_file = caller[0].split('/').last
puts "jinyu.debug: #{caller_file} calls #{method_name}, #{method_args.map(&:class)}"
self_class.instance_method("__#{method_name}".to_sym).bind(self).call(*method_args, &block)
end
end
end
end
|