Class: Method::Composition
- Defined in:
- lib/core/facets/method/composition.rb
Overview
Method Composition class acts a proxy for composed methods.
Instance Method Summary collapse
- #*(h) ⇒ Object
- #[](*x) ⇒ Object
- #^(n) ⇒ Object
- #arity ⇒ Object
- #call(*x) ⇒ Object
-
#initialize(*f) ⇒ Composition
constructor
A new instance of Composition.
- #inspect ⇒ Object
- #owner ⇒ Object
- #receiver ⇒ Object
- #to_proc ⇒ Object
Constructor Details
#initialize(*f) ⇒ Composition
Returns a new instance of Composition.
14 15 16 |
# File 'lib/core/facets/method/composition.rb', line 14 def initialize(*f) @f = f end |
Instance Method Details
#*(h) ⇒ Object
25 26 27 28 |
# File 'lib/core/facets/method/composition.rb', line 25 def *(h) #Composition.new(self, h) @f << h end |
#[](*x) ⇒ Object
71 72 73 |
# File 'lib/core/facets/method/composition.rb', line 71 def [](*x) call(*x) end |
#^(n) ⇒ Object
31 32 33 34 35 36 37 38 |
# 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 ⇒ Object
51 52 53 |
# File 'lib/core/facets/method/composition.rb', line 51 def arity @f.last.arity end |
#call(*x) ⇒ Object
62 63 64 65 66 67 68 |
# 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 ⇒ Object
19 20 21 22 |
# File 'lib/core/facets/method/composition.rb', line 19 def inspect x = @f.map{ |f| f.inspect }.join(' * ') "#<Method::Composition: #{x}>" end |
#owner ⇒ Object
41 42 43 |
# File 'lib/core/facets/method/composition.rb', line 41 def owner @f.last.owner end |
#receiver ⇒ Object
46 47 48 |
# File 'lib/core/facets/method/composition.rb', line 46 def receiver @f.first.receiver end |