Update connect/disconnect action states.
[kaya.git] / lib / factory.rb
blob928c28c4dc02911c08b99ce1c803faa9cfe7a542
1 # Copyright (c) 2009 Paolo Capriotti <p.capriotti@gmail.com>
2
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 2 of the License, or
6 # (at your option) any later version.
8 class Proc
9   def bind(object)
10     block, time = self, Time.now
11     (class << object; self end).class_eval do
12       method_name = "__bind_#{time.to_i}_#{time.usec}"
13       define_method(method_name, &block)
14       method = instance_method(method_name)
15       remove_method(method_name)
16       method
17     end.bind(object)
18   end
19 end
21 class Factory
22   attr_reader :component
24   def initialize(klass = nil, &blk)
25     @blk = blk
26     @component = klass
27   end
28   
29   def new(*args)
30     @blk[*args]
31   end
32   
33   def __bind__(object)
34     Factory.new(@component, &@blk.bind(object))
35   end
36 end