Class: MetaFactory
Instance Method Summary collapse
- #create(prefix_args = [], postfix_args = [], &block) ⇒ Object (also: #new)
-
#initialize(aClass, *a, &b) ⇒ MetaFactory
constructor
A new instance of MetaFactory.
-
#record(&block) ⇒ Object
Record a block of actions which will be applied on the created object.
Constructor Details
#initialize(aClass, *a, &b) ⇒ MetaFactory
Returns a new instance of MetaFactory.
9 10 11 12 |
# File 'lib/meta_factory.rb', line 9 def initialize ( aClass, *a, &b ) @record = nil @class, @args, @block = aClass, a, b end |
Instance Method Details
#create(prefix_args = [], postfix_args = [], &block) ⇒ Object Also known as: new
14 15 16 17 18 19 20 |
# 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(&block) ⇒ Object
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])
34 35 36 |
# File 'lib/meta_factory.rb', line 34 def record ( &block ) @record = block end |