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, g) ⇒ Composition
constructor
A new instance of Composition.
- #inspect ⇒ Object
- #owner ⇒ Object
- #receiver ⇒ Object
- #to_proc ⇒ Object
Constructor Details
#initialize(f, g) ⇒ Composition
Returns a new instance of Composition.
9 10 11 12 |
# File 'lib/core/facets/method/composition.rb', line 9 def initialize(f,g) @f = f @g = g end |
Instance Method Details
#*(h) ⇒ Object
15 16 17 |
# File 'lib/core/facets/method/composition.rb', line 15 def *(h) Composition.new(self, h) end |
#[](*x) ⇒ Object
56 57 58 |
# File 'lib/core/facets/method/composition.rb', line 56 def [](*x) call(*x) end |
#^(n) ⇒ Object
20 21 22 23 |
# File 'lib/core/facets/method/composition.rb', line 20 def ^(n) return self if n < 2 Composition.new(self, self ^ (n-1)) end |
#arity ⇒ Object
41 42 43 |
# File 'lib/core/facets/method/composition.rb', line 41 def arity @g.arity end |
#call(x) ⇒ Object
51 52 53 |
# File 'lib/core/facets/method/composition.rb', line 51 def call(x) @f.call(*@g.call(*x)) end |
#inspect ⇒ Object
36 37 38 |
# File 'lib/core/facets/method/composition.rb', line 36 def inspect "#<Method::Composition: #{@f.inspect} * #{@g.inspect}>" end |
#owner ⇒ Object
26 27 28 |
# File 'lib/core/facets/method/composition.rb', line 26 def owner @g.owner end |
#receiver ⇒ Object
31 32 33 |
# File 'lib/core/facets/method/composition.rb', line 31 def receiver @g.receiver end |
#to_proc ⇒ Object
46 47 48 |
# File 'lib/core/facets/method/composition.rb', line 46 def to_proc Proc.new {|x| @f.call(*@g.call(*x)) } end |