arrays - Use ruby each method and store unique results in their own variables -


i new world of programming , appreciate in executing following:

i want use '.each' statement iterate through data. there, need store each iteration separately. please see coding example below.

array1 = []  array2 = []  array3 = []  array4 = []  array5 = []  array6 = []  array7 = []  array8 = []  array9 = []  array10 = []   @images_array.each |info|   t = info[:title]   = info[:artist]   m = info[:medium]   c = info[:collection]   array.new << t << << m << c end  

just clear, have 10 arrays. want store title, artist, medium, , collection information of 10 different items in own arrays. how can add on each method allow executed dynamically? last line of code allow me away 10 arrays top. problem array.new method, however, have no way of retrieving specific array. items neatly stored there no variable storing arrays.

also, if can think of better method of doing this, please share well. thank you.

you can take below approach:

@images_array.each_with_object([]) |info,a|   a.push(info.values_at(:title,:artist,:medium,:collection)) end  

Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -