lib/beethoven/composer.rb in beethoven-0.0.2 vs lib/beethoven/composer.rb in beethoven-0.1.0

- old
+ new

@@ -1,19 +1,20 @@ module Beethoven + # Composer composes class instantiation. The first call to new refers to the + # `initialize` method, and creates an object which duck-types Class.new. When + # `Composer#new` is called, the classes are instantiated in order, where the + # argument passed to the first class is the argument passed to Composer#new, + # and each subsequent class receives the instantiated object as its argument. class Composer def initialize(*fs) - @fs = fs + @fs = if fs.size == 1 && fs[0].is_a?(Array) + fs[0] + else + fs + end end def new(x) @fs.reduce(x) { |a, e| e.new(a) } - end - - def *(other) - self.class.new(other, self) - end - - def |(other) - self.class.new(self, other) end end end