Class: MethodDecorators::Memoize
- Defined in:
- lib/method_decorators/memoize.rb
Instance Method Summary collapse
- #call(orig, this, *args, &blk) ⇒ Object
-
#initialize ⇒ Memoize
constructor
A new instance of Memoize.
Methods inherited from Decorator
Constructor Details
#initialize ⇒ Memoize
Returns a new instance of Memoize.
5 6 7 |
# File 'lib/method_decorators/memoize.rb', line 5 def initialize @memo_ivar = "@_memoize_cache#{rand(10**10)}" end |
Instance Method Details
#call(orig, this, *args, &blk) ⇒ Object
9 10 11 12 |
# File 'lib/method_decorators/memoize.rb', line 9 def call(orig, this, *args, &blk) return cache(this)[args] if cache(this).has_key?(args) cache(this)[args] = orig.call(*args, &blk) end |