Hi all I know that classes are some sort of Constants in ruby. Now I have to dynamically call a class'' method while the class'' name is in a string. string = "MyCoolClass" Now I wanna call MyCoolClass.my_cool_method but I only have the string "string". You know what I mean? Thanks :-) Josh -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Joshua Muheim wrote:> string = "MyCoolClass" > > Now I wanna call MyCoolClass.my_cool_method but I only have the string > "string". You know what I mean?string.constantize.my_cool_method -- Jakob Skjerning - http://mentalized.net --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On 9/25/06, Jakob Skjerning <jakob-pixy5vpirPnEueBKFXcDjA@public.gmane.org> wrote:> > Joshua Muheim wrote: > > string = "MyCoolClass" > > > > Now I wanna call MyCoolClass.my_cool_method but I only have the string > > "string". You know what I mean? > > string.constantize.my_cool_method > > -- > Jakob Skjerning - http://mentalized.net >Or in plain Ruby: Object.const_get("MyCoolClass").my_cool_method Max --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---