On 01/12/06, xTRiM <rtokarev / gmail.com> wrote:
> I know what this is about Abstract Factory pattern. But in example at
> rubygarden we passing a class to factory and it creates an object from
> it.
> But how can i pass a text string to factory which will create an object
> from it?
> In later example: i wish to pass string "Foo" or "Bar" not Foo or Bar.
>
>
> ------ From rubygarden library of patterns ------
> class Foo; end
> class Bar; end
>
> # Here is the use of the Abstract Factory pattern
> def create_something( factory )
>     new_object = factory.new
>     puts "created a new #{new_object.class} with a factory"
> end
>
> # Here we select a factory to use
> create_something( Foo )
> create_something( Bar )
>
> Running the code above results in the output:
> created a Foo with a factory
> created a Bar with a factory

create_something(Kernel.const_get("Foo"))

Farrel