31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
# File 'lib/erp_base_erp_svcs/extensions/core/acts_as_aspector_on.rb', line 31
def acts_as_aspector_on(*meth_names)
self.instance_eval do
define_singleton_method :before do |method_name, &blk|
if meth_names.include?(method_name)
m = instance_method(method_name)
define_method(method_name) do |*args, &block|
blk.call(self) unless blk.nil?
m.bind(self).call(*args, &block)
end
end
end
define_singleton_method :after do |method_name, &blk|
if meth_names.include?(method_name)
m = instance_method(method_name)
define_method(method_name) do |*args, &block|
result = m.bind(self).call(*args, &block)
blk.call(self, result) unless blk.nil?
result
end
end
end
end
end
|