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

By definition a Functor is simply a first class method, but these are common in the form of Method and Proc. So for Ruby a Functor is a more specialized as a Higher-order function or Metafunction. Essentally, a Functor can vary its behavior accorrding to the operation applied to it.

  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

method_missing   new   to_proc  

Constants

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

External Aliases

class -> __class__
 

Public Class methods

[Source]

# File lib/facets/core/facets/functor.rb, line 50
  def initialize(&function)
    @function = function
  end

Public Instance methods

[Source]

# File lib/facets/core/facets/functor.rb, line 55
  def to_proc
    @function
  end

Private Instance methods

Any action against the functor is processesd by the function.

[Source]

# File lib/facets/core/facets/functor.rb, line 72
  def method_missing(op, *args, &blk)
    @function.call(op, *args, &blk)
  end

[Validate]