Hello Rubyites, Seems like this is a newbie question but want to get rid of it asap. Googled but found nothing. I have some arrays(10 arrays) which i am using in my code. Now declaraing/defining each/every array is redudant code as like array1, array2... array10 = [], [],...[] Is there any other possible solution to this? -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
array1= array2... = array10 = [] On Tue, Jan 11, 2011 at 12:33 PM, Hemant Bhargava <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org>wrote:> Hello Rubyites, > > Seems like this is a newbie question but want to get rid of it asap. > Googled but found nothing. > > I have some arrays(10 arrays) which i am using in my code. Now > declaraing/defining each/every array is redudant code as like > array1, array2... array10 = [], [],...[] > > Is there any other possible solution to this? > > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- sαη∂ιρ Rαηѕιηg --- blog www.funonrails.com twitter @sandipransing skype sandip.ransing -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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.
I am sorry but i knew that as well. Is there any way to do it using foreach method. I mean like:- 1.upto 10 do { |i| "array#i" = [] } Sandip Ransing wrote in post #973867:> array1= array2... = array10 = [] > > On Tue, Jan 11, 2011 at 12:33 PM, Hemant Bhargava > <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org>wrote: > >> >> For more options, visit this group at >> http://groups.google.com/group/rubyonrails-talk?hl=en. >> >> > > > -- > sαη∂ιρ Rαηѕιηg > > --- > blog www.funonrails.com > twitter @sandipransing > skype sandip.ransing-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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.
On 11 Jan 2011, at 07:40, Sandip <san2821-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> array1= array2... = array10 = []This is very different - array1, array2 are being set to the same array rather than all being set to separate empty arrays. I can''t think of a more concise way of creating 10 arrays other than not doing it: if you have that much state you are accumulating, perhaps you would be served by an array of your own data structures or something like that Fred> > On Tue, Jan 11, 2011 at 12:33 PM, Hemant Bhargava <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: > Hello Rubyites, > > Seems like this is a newbie question but want to get rid of it asap. > Googled but found nothing. > > I have some arrays(10 arrays) which i am using in my code. Now > declaraing/defining each/every array is redudant code as like > array1, array2... array10 = [], [],...[] > > Is there any other possible solution to this? > > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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. > > > > > -- > sαη∂ιρ Rαηѕιηg > > --- > blog www.funonrails.com > twitter @sandipransing > skype sandip.ransing > > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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.-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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.
If the data you are supplying for your arrays is random then I would go with just a multidimensional array, smth. like this: a = [ [1,2,3,4], [5,6,7,8], [9,10,11,12], [13,14,15,16] ]. But you your data is more predictable and can be expressed with code / algorithm, then try using iterator: length = 10 a = Array.new(length) length.times do |i| a[i] = %w(this is an array of strings) end -- Thanks, Ivan Povalyukhin (http://twitter.com/@ivanpovalyukhin) On Jan 10, 11:55 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 11 Jan 2011, at 07:40, Sandip <san2...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > array1= array2... = array10 = [] > > This is very different - array1, array2 are being set to the same array rather than all being set to separate empty arrays. > > I can''t think of a more concise way of creating 10 arrays other than not doing it: if you have that much state you are accumulating, perhaps you would be served by an array of your own data structures or something like that > > Fred > > > > > > > > > > > On Tue, Jan 11, 2011 at 12:33 PM, Hemant Bhargava <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: > > Hello Rubyites, > > > Seems like this is a newbie question but want to get rid of it asap. > > Googled but found nothing. > > > I have some arrays(10 arrays) which i am using in my code. Now > > declaraing/defining each/every array is redudant code as like > > array1, array2... array10 = [], [],...[] > > > Is there any other possible solution to this? > > > -- > > Posted viahttp://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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > For more options, visit this group athttp://groups.google.com/group/rubyonrails-talk?hl=en. > > > -- > > sαη∂ιρ Rαηѕιηg > > > --- > > blogwww.funonrails.com > > twitter @sandipransing > > skype sandip.ransing > > > -- > > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > For more options, visit this group athttp://groups.google.com/group/rubyonrails-talk?hl=en.-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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.