Class: Method
- Defined in:
- lib/core/facets/method/memoize.rb,
lib/core/facets/method/composition.rb
Defined Under Namespace
Classes: Composition
Instance Method Summary collapse
-
#*(g) ⇒ Object
Method composition.
-
#^(n) ⇒ Object
Method repetition.
-
#memoize(value) ⇒ Object
Memoize a method by defining a singleton override.
Instance Method Details
#*(g) ⇒ Object
Method composition.
65 66 67 |
# File 'lib/core/facets/method/composition.rb', line 65 def *(g) Composition.new(self, g) end |
#^(n) ⇒ Object
Method repetition.
72 73 74 75 76 77 78 |
# File 'lib/core/facets/method/composition.rb', line 72 def ^(n) if n < 2 self else Composistion.new(self, self ^ (n-1)) end end |
#memoize(value) ⇒ Object
Memoize a method by defining a singleton override.
NOTE: This method is not a common core extension and is not loaded automatically when using require 'facets'.
11 12 13 14 |
# File 'lib/core/facets/method/memoize.rb', line 11 def memoize(value) singleton = (class << receiver; self; end) singleton.__send__(:define_method, name){ value } end |