[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

how to create classes automatically

markusjais

8/3/2006 11:40:00 AM

hi

let's say I have a string with a class name as a value.
I want to create a new instance of the class with the given class name.

example:
when I have a string like this:

str = "Array"

I want to create a new Array class base on the information in str.

any ideas how this could be done ?

thanks a lot

Markus
3 Answers

chrisjroos@gmail.com

8/3/2006 11:51:00 AM

0

Object.const_get("Array").new

On 8/3/06, markusjais@gmx.de <markusjais@gmx.de> wrote:
> hi
>
> let's say I have a string with a class name as a value.
> I want to create a new instance of the class with the given class name.
>
> example:
> when I have a string like this:
>
> str = "Array"
>
> I want to create a new Array class base on the information in str.
>
> any ideas how this could be done ?
>
> thanks a lot
>
> Markus
>
>

Sander Land

8/3/2006 11:52:00 AM

0

On 8/3/06, markusjais@gmx.de <markusjais@gmx.de> wrote:
> I want to create a new Array class base on the information in str.
> any ideas how this could be done ?

str = "Array"
Object.const_get(str).new

markusjais

8/3/2006 12:16:00 PM

0

thank you very much.

Markus

Chris Roos wrote:

> Object.const_get("Array").new
>
> On 8/3/06, markusjais@gmx.de <markusjais@gmx.de> wrote:
>> hi
>>
>> let's say I have a string with a class name as a value.
>> I want to create a new instance of the class with the given class name.
>>
>> example:
>> when I have a string like this:
>>
>> str = "Array"
>>
>> I want to create a new Array class base on the information in str.
>>
>> any ideas how this could be done ?
>>
>> thanks a lot
>>
>> Markus
>>
>>