From: Siep Korteling Date: 2008-06-28T08:41:48+09:00 Subject: Re: Creating a variable based on array Tj Superfly wrote: > Thank you both for your replies. :) I used the 2nd one and it worked > beautifully. > > I have another question though, how can I get it to generate urls at a > time, such as > > array = colors.map do |color| > "http://www.mysite.com/file1/#{petpet}_#{color}.gif", > "http://www.mysite.com/file2/#{petpet}_#{color}.gif" > end > > Note the different files. :) > > The comma doesn't work, and neither does removing it. So, is there a > trick to getting it to do more than one line? Maybe something like this: array = colors.map do |color| ["http://www.mysite.com/file1/#{petpet}_#{color}.gif", "http://www.mysite.com/file2/#{petpet}_#{color}.gif"] end array.flatten! or array = colors.inject(Array.new) do |ar, color| ar << "http://www.mysite.com/file1/#{petpet}_#{color}.gif" ar << "http://www.mysite.com/file2/#{petpet}_#{color}.gif" end Regards, Siep -- Posted via http://www.ruby-forum.com/.