Parent

Functor

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

Public Class Methods

new(&function) click to toggle source
    # File lib/core/facets/functor.rb, line 63
63:   def initialize(&function)
64:     @function = function
65:   end

Public Instance Methods

method_missing(op, *args, &blk) click to toggle source

Any action against the functor is processesd by the function.

    # File lib/core/facets/functor.rb, line 72
72:   def method_missing(op, *args, &blk)
73:     @function.call(op, *args, &blk)
74:   end
to_proc() click to toggle source
    # File lib/core/facets/functor.rb, line 67
67:   def to_proc
68:     @function
69:   end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.