Create an object of a type (class) stored in a string

Send to friend

So, you have a class of object stored in a string, and you want to create an object of that class. You cannot assign a type of an object directly (by say @myvar.class = xxx), and the class conversions are limited to the basic built-in classes like to_s, etc. But you can use this trick:


@classtype = "Artist"
@myvar = Kernel.const_get(@classtype).find(@id)