11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
# File 'lib/method_watcher.rb', line 11
def included mod
MethodWatcher.init_method_watcher mod
mod.singleton_class.class_eval do
def watch_methods *methods
if methods.empty?
@_watch_method = true
else
methods.each do |method|
@_watch_methods[method.to_sym] = self
end
end
end
def unwatch_methods *methods
if methods.empty?
@_watch_method = false
else
methods.each do |method|
@_watch_methods.delete method.to_sym
end
end
end
def method_added method
super
if @_watch_methods.has_key?(method.to_sym)
@_watch_methods[method].method_overriding method
end
watch_methods method if @_watch_method
end
def method_overriding method
warn "method #{self}##{method} is overridden"
end
def inherited mod
super
MethodWatcher.init_method_watcher mod
end
end
end
|