2
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/wrapit/method_wrappable.rb', line 2
def self.included(base)
class << base
private
def method_wrappable(*args)
args.each do |method|
mw_create_naked_method(method)
mw_create_wrapped_method(method)
end
end
def mw_create_naked_method(method)
raise Wrapit::InvalidCallerError unless caller[0] =~ /method_wrappable/
define_method :"#{method}_naked" do |*args|
self.class.superclass.instance_method(method).bind(self).call(*args)
end
end
def mw_create_wrapped_method(method)
raise Wrapit::InvalidCallerError unless caller[0] =~ /method_wrappable/
define_method method do |*args|
super(*args).wrapped
end
end
end
end
|