Ok so could anyone tell me what this is called so I can look it up rather posting questions in this forum all the time. I have had to post something to learn how to do the following: Model.send("field#{x}") and session["field#{x}".to_sym] now I am trying to do this for variables for example: @details = RDetails.find(id) 1.upto(15) do |x| @details.?????("field#{x}") end @details.save I don''t even know what to look up. I tried string methods, model methods, variable methods... Thanks in advance -- 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 -~----------~----~----~----~------~----~------~--~---
> Ok so could anyone tell me what this is called so I can look it up > rather posting questions in this forum all the time. I have had to post > something to learn how to do the following: > > Model.send("field#{x}") > > and > > session["field#{x}".to_sym] >now I am trying to do this for variables for example:> > @details = RDetails.find(id) > 1.upto(15) do |x| > @details.?????("field#{x}") > end > @details.save > > > I don''t even know what to look up. I tried string methods, model > methods, variable methods...What are you trying to do there? Set those fields? Otherwise I doin''t see what the point is... I''m thinking you maybe want: @details.send("field#{x}=", "some val here") That would set all those fields to "some val here". -philip --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Sorry about that I meant to say: @details.?????("field#{x}") = "some value" And what you said works perfect, that''s exactly what I was trying to do. I understood what the .send was doing before, I didn''t realize I could also use that to set the values as well using: @details.send("field#{x}=", "some val here") Thanks a lot -- 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 -~----------~----~----~----~------~----~------~--~---
On Thu, Mar 13, 2008 at 8:54 AM, Chris Hickman <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Sorry about that I meant to say: > And what you said works perfect, that''s exactly what I was trying to do. > I understood what the .send was doing before, I didn''t realize I could > also use that to set the values as well using:As a pointer, ruby is an object oriented language, that means the objects pass messages to each other in what we commonly call method_calls. So, @person.first_name is a way of sending the ''first_name'' message to the @person object. It is equiv to @person.send(:first_name) If we wanted to set the first name of a person we could type: @person.first_name = ''Mikel'' But we could also type: @person.send(:first_name=, ''Mikel'') I would recommend you to get the latest version of the Pickaxe Ruby book, it will teach you a lot about these things. Later Mikel http://lindsaar.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?hl=en -~----------~----~----~----~------~----~------~--~---