Class: Beethoven::Composer

Inherits:
Object show all
Defined in:
lib/beethoven/composer.rb

Overview

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.

Instance Method Summary collapse

Constructor Details

#initialize(*fs) ⇒ Composer

Returns a new instance of Composer.



8
9
10
11
12
13
14
# File 'lib/beethoven/composer.rb', line 8

def initialize(*fs)
  @fs = if fs.size == 1 && fs[0].is_a?(Array)
          fs[0]
        else
          fs
        end
end

Instance Method Details

#new(x) ⇒ Object



16
17
18
# File 'lib/beethoven/composer.rb', line 16

def new(x)
  @fs.reduce(x) { |a, e| e.new(a) }
end