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.
--
marko schulz
Dieser Satz beinhalten drei Fehller.