Module: Memoizable

Included in:
Amazon::MWS::Authentication::Signature
Defined in:
lib/amazon/mws/lib/memoizable.rb

Instance Method Summary collapse

Instance Method Details

#memoize(name, cache = Hash.new) ⇒ Object



2
3
4
5
6
7
8
9
# File 'lib/amazon/mws/lib/memoizable.rb', line 2

def memoize( name, cache = Hash.new )
  original = "__unmemoized_#{name}__"
  ([Class, Module].include?(self.class) ? self : self.class).class_eval do
    alias_method original, name
    private original
    define_method(name) { |*args| cache[args] ||= send(original, *args) }
  end
end