On 6/23/05, R. Mark Volkmann <mark / ociweb.com> wrote:
> How can I create a Class object from a String that contains the name of a class?
> For example, after
> 
> clazz = Array
> 
> the variable clazz holds a Class object representing the class Array.
> I want to start with a string like this.
> 
> name = 'Array'
> clazz = ???

For top-level objects, this is as simple as:

  name = 'Array'
  klass = Object.const_get(name)
  p klass # => Array

For nested values, it's:

  name = 'Transaction::Simple::Group'
  klass = name.split(/::/).inject(Object) { |k, n| k.const_get(n) }
  p klass # => Transaction::Simple::Group

-austin
-- 
Austin Ziegler * halostatue / gmail.com
               * Alternate: austin / halostatue.ca