class Method::Composition
Method
Composition
class acts a proxy for composed methods.
@author Mike Burns
Public Class Methods
new(*f)
click to toggle source
# File lib/core/facets/method/composition.rb, line 14 def initialize(*f) @f = f end
Public Instance Methods
*(h)
click to toggle source
# File lib/core/facets/method/composition.rb, line 25 def *(h) #Composition.new(self, h) @f << h end
[](*x)
click to toggle source
# File lib/core/facets/method/composition.rb, line 71 def [](*x) call(*x) end
^(n)
click to toggle source
# File lib/core/facets/method/composition.rb, line 31 def ^(n) raise ArgumentError if n < 0 return self if n < 2 #Composition.new(self, self ^ (n-1)) (n - 1).times{ @f = @f.concat(@f) } end
arity()
click to toggle source
# File lib/core/facets/method/composition.rb, line 51 def arity @f.last.arity end
call(*x)
click to toggle source
# File lib/core/facets/method/composition.rb, line 62 def call(*x) r = x @f.reverse_each do |f| r = f.call(*r) end r end
inspect()
click to toggle source
# File lib/core/facets/method/composition.rb, line 19 def inspect x = @f.map{ |f| f.inspect }.join(' * ') "#<Method::Composition: #{x}>" end
owner()
click to toggle source
# File lib/core/facets/method/composition.rb, line 41 def owner @f.last.owner end
receiver()
click to toggle source
# File lib/core/facets/method/composition.rb, line 46 def receiver @f.first.receiver end
to_proc()
click to toggle source
# File lib/core/facets/method/composition.rb, line 56 def to_proc #Proc.new {|x| @f.call(*@g.call(*x)) } Proc.new { |*x| call(*x) } end