Class Functor
In: lib/core/facets/functor.rb
Parent: Object

Functor is Ruby‘s implementation of a Higher-Order-Message. Essentally, a Functor can vary its behavior accorrding to the operation applied to it.

Example

  f = Functor.new { |op, x| x.send(op, x) }
  (f + 1)  #=> 2
  (f + 2)  #=> 4
  (f + 3)  #=> 6
  (f * 1)  #=> 1
  (f * 2)  #=> 4
  (f * 3)  #=> 9

Methods

cache   new   to_proc  

Constants

EXCEPTIONS = [:binding, :inspect, :object_id]

External Aliases

class -> __class__
 

Public Class methods

Functors can be somewhat inefficient if a new Functor is frequently recreated for the same use. So this cache can be used to speed things up.

The key will always be an array, wich makes it easier to cache Functor for multiple factors.

Public Instance methods

[Validate]