| Class | MetaFactory |
| In: |
lib/meta_factory.rb
|
| Parent: | Object |
| Copyright: | Copyright (c) 2005 Nicolas Pouillard. All rights reserved. |
| Author: | Nicolas Pouillard <ertai@lrde.epita.fr>. |
| License: | Gnu General Public License. |
| Revision: | $Id: /w/fey/ruby_ex/trunk/lib/meta_factory.rb 7954 2005-09-12T07:59:21.074304Z ertai $ |
# File lib/meta_factory.rb, line 9 def initialize ( aClass, *a, &b ) @record = nil @class, @args, @block = aClass, a, b end
# File lib/meta_factory.rb, line 14 def create ( prefix_args=[], postfix_args=[], &block ) args = prefix_args + @args + postfix_args block = @block if block.nil? anObject = @class.new(*args, &block) @record[anObject] unless @record.nil? anObject end
Record a block of actions which will be applied on the created object
Example: factory = MetaFactory.new(MyClass, some, args, …) factory.record do |o|
o.foo = bar o.flou! ...
end factory.create([some, args, to, prepend], [some, to append])
# File lib/meta_factory.rb, line 34 def record ( &block ) @record = block end