class Abc
end #=> nil
klass = eval("Abc") #=> Abc
klass.new #=> #<Abc:0x37643e8>
Assumes there really is a class with the name provided...
In ActiveSupport, there was String#constantize, which did the same thing, but I believe it's deprecated after 2.1.
EDIT: this is the implementation of constantize from ActiveSupport 2.1.2:
def constantize(camel_cased_word)
names = camel_cased_word.split('::')
names.shift if names.empty? || names.first.empty?
constant = Object
names.each do |name|
constant = constant.const_defined?(name) ? constant.const_get(name) : constant.const_missing(name)
end
constant
end