From: Raimon Fs Date: 2007-12-07T05:12:21+09:00 Subject: Re: array iterator that have more arrays that also need iter Xavier Noria wrote: > On Dec 6, 2007, at 8:25 PM, Raimon Fs wrote: > >> I have one array, and each element of this array, has another array. > > >> 700_tax: "17.91" >> 82567.36 95778.21 13210.85 >> 17.91 255.81 273.72 >> 707.59 0.0 707.59 > > Looks like you have a collection of InvoicesCalcul, each of them with > an accessor "attributes", which is a hash: > > values = invoice_calculs.map do |ic| > ic.attributes > end.map do |a| > a.values > end.flatten > > Those could be AR objetcs, in Rails you can write that this way: > > values = invoice_calculs.map(&:attributes).map(&:values).flatten thanks ... maybe they are AR, because I get those values from a loop, where I issue some sql: @temp_result = InvoicesCalcul.find_by_sql('SELECT sum(base) AS "'+ @name_base + '" ,sum(import) AS "' + @name_tax + '" ,sum(total_net) AS "' + @name_total + '" FROM invoices_calculs c, invoices i WHERE c.tipus='+KIND_TAX_IVA.to_s+' AND c.invoice_id=i.id AND c.xcent='+ @value +' AND i.any='+@c_year) and I add those results into an array. what I see, with your suggestion, I have the same issue as before, I want to retrieve the values without knowing the attribute, only by the index: now I have to a['1600_base'] to get the value, I just want the value for each index, not the attribute. i'm going to deep into the rail's book ... thanks, raimon -- Posted via http://www.ruby-forum.com/.