Class: MetaFactory

Inherits:
Object show all
Defined in:
lib/meta_factory.rb

Instance Method Summary collapse

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