Hello List! I come to you after a long while of troubleshooting and researching to no avail. My wish is to reference a class variable whose name is stored as a string in another variable. I will try to set up an example: variable_name = ''text'' print @#{variable_name} I think that is how it would work, and i think the syntax is nearly correct, but... its not. Any help? Thanks alot guys! --nathan --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
> I come to you after a long while of troubleshooting and researching to > no avail. My wish is to reference a class variable whose name is > stored as a string in another variable. I will try to set up an > example: > > variable_name = ''text'' > print @#{variable_name} > > I think that is how it would work, and i think the syntax is nearly > correct, but... its not. > > Any help? Thanks alot guys!Not quite the same, but let''s say you have an AR model named Foo that has an attribute named bar, then: myfoo = Foo.find(:first) myfoo.send(''bar'') # same as myfoo.bar Maybe that will get you closer... --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On 1/12/07, BlackNute <blacknute-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> variable_name = ''text'' > print @#{variable_name}instance_variable_get("@#{variable_name") http://ruby-doc.org/core/ -- Chris Wanstrath http://errtheblog.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?hl=en -~----------~----~----~----~------~----~------~--~---
On 1/17/07, Chris Wanstrath <chris-G5sj8e7vJc8@public.gmane.org> wrote:> On 1/12/07, BlackNute <blacknute-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > variable_name = ''text'' > > print @#{variable_name} > > instance_variable_get("@#{variable_name")Whoops, should be instance_variable_get("@#{variable_name}") of course. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
> variable_name = ''text'' > print @#{variable_name}eval("print #{variable_name}") -- Nedforce Informatica Specialisten B.V. http://www.nedforce.nl +31 (0)53 4500225 --~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
BlackNute wrote:> Hello List! > > I come to you after a long while of troubleshooting and researching to > no avail. My wish is to reference a class variable whose name is > stored as a string in another variable. I will try to set up an > example: > > variable_name = ''text'' > print @#{variable_name}I had asked questions like this. http://www.ruby-forum.com/topic/93236#187853 http://www.ruby-forum.com/topic/93682#189535 -- 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?hl=en -~----------~----~----~----~------~----~------~--~---