Peter Smith
2007-Feb-23 01:54 UTC
[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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Michael Schuerig
2007-Feb-23 02:27 UTC
Re: [RoR],[C.L.R] How I convert a string object into a class?
On Friday 23 February 2007, Peter Smith wrote:> 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 > => PersonHas been discussed over and over. Look in the API docs for #constantize and search this mailing list for it. HTH, Michael -- Michael Schuerig mailto:michael-q5aiKMLteq4b1SvskN2V4Q@public.gmane.org http://www.schuerig.de/michael/ --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Peter Smith
2007-Feb-23 04:25 UTC
Re: [RoR],[C.L.R] How I convert a string object into a class?
Demo: my_class = "Person".camelize.constantize -Peter --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---