Hello, I''m struggling with this stuff and can''t find an answer so please advise. What I''m trying to achieve @collection has 7 elements I want to: - cycle through all those elements - assign element["smth"] through element["smth3"] to @data.set1_smth through @data.set1_smth3 - the last iteration would be assigning element["smth"] to @data.set7_smthetc I just don''t seem to grasp how to change @data.set1_smth into @ data.set2_smth etc. when iterating the block. i = 1 @collection.elements.each do |item| @data.set1_smth = item.elements["smth"] # obviously @ data.set1_smth should be somehow different @data.set1_smth2 = item.elements["smth2"] @data.set1_smth3 = item.elements["smth3"] i += 1 end Can anybody help? I tried @data.send("set" + i + "_smth") but that didn''t seem to work. Thanks in advance. Radek --~--~---------~--~----~------------~-------~--~----~ 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 19 Oct 2007, at 11:19, [s] wrote:> > Can anybody help? > I tried @data.send("set" + i + "_smth") but that didn''t seem to work. > Thanks in advance.This is a ruby rather than a rails question, but you need to send the method name "set1_smth=", and pass the value to be set as the next argument Fred> > > Radek > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---