Class: Method

Inherits:
Object show all
Defined in:
lib/core-uncommon/facets/method/memoize.rb

Instance Method Summary collapse

Instance Method Details

#memoize(value) ⇒ Object

Memoize a method by defining a singleton override.

NOTE: This is not (presently) a common core extension and is not loaded automatically when using require 'facets'.



7
8
9
10
# File 'lib/core-uncommon/facets/method/memoize.rb', line 7

def memoize(value)
  singleton = (class << receiver; self; end)
  singleton.__send__(:define_method, name){ value }
end