3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
# File 'lib/lab419/core/memoization.rb', line 3
def memoize *method_symbols
method_symbols.each do | method_symbol |
mthd = instance_method method_symbol
remove_method method_symbol
already_called = {}
results = {}
define_method method_symbol do |*args, &blk|
ac = already_called[[args,blk]]
return results[[args,blk]] if already_called[[args,blk]]
already_called[[args,blk]] = true
results[[args,blk]] = mthd.bind( self ).(*args, &blk)
end
end
self
end
|