In article <20010423092940.A5222 / scheibenwelt>,
Marko Schulz  <in6x059 / public.uni-hamburg.de> wrote:
>On Mon, Apr 23, 2001 at 06:40:08AM +0900, Phil Tomson wrote:
>> 
>> [ Getting a Class by its name as String ]
>
>You could simply use an eval:
>
>  module ObjectSpace
>    def ObjectSpace.class(name)
>      eval(name)
>    end
>  end
>
>
>You might want to add some error checking:
>
>
>  module ObjectSpace
>    def ObjectSpace.class(name)
>      return nil if not (validClassname?(name) and eval(name).kind_of? Class)
>
>      eval(name)
>    end
>
>    def ObjectSpace.validClassname?(name)
>       name =~ /^[A-Z][a-zA-Z0-9]*$/
>    end
>  end
>
>If you are concerned about performance you could remove the doubled
>eval, but then again if you are concerned about performance you should
>implement it native anyway.
>

Like I said in the original post, I know there are many ways to do it, I 
just want to see a single method that does this (gets a Class from a 
String) so that it's easy for newbies and even oldbies who don't want to 
have to go to a lot of trouble.  Also, I don't think using eval for this 
is a good idea.

Phil