[RoR],[C.L.R] How I convert a string object into a class?

People,

Lately I’ve been using the .name() method of classes.

For example:

Person.name => “Person”

Today… I’d like to do the inverse:

“Person”.to_class => Person

How do I transform a string into a class? I’m working with a Rails app where I need to get names of AR classes at run-time.

-Peter

Has been discussed over and over. Look in the API docs for #constantize and search this mailing list for it.

HTH, Michael

Demo:

my_class = “Person”.camelize.constantize

-Peter