Class: Method

Inherits:
Object show all
Defined in:
lib/core/facets/method/memoize.rb,
lib/core/facets/method/composition.rb

Defined Under Namespace

Classes: Composition

Instance Method Summary collapse

Instance Method Details

#*(g) ⇒ Object

Method composition.

Author:

  • Mike Burns



65
66
67
# File 'lib/core/facets/method/composition.rb', line 65

def *(g)
  Composition.new(self, g)
end

#^(n) ⇒ Object

Method repetition.

Author:

  • Mike Burns



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'.

Uncommon:

  • require ‘facets/method/memoize’



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