From: James Edward Gray II Date: 2011-02-02T00:16:43+09:00 Subject: Re: looping CSV.foreach?? On Jan 31, 2011, at 10:51 PM, Kamarulnizam Rahim wrote: > I use the following codes: > > CSV.foreach('ActionPlan.csv') do |row| > next unless row[0] =~ /2.[a-z]/ > t = Target.new > t.question = row[1] > pp t.question > end > > And get the following results: > > "Routinely monitor energy use", > "Identify major energy uses", > "Improve inspection and maintenance procedures", > "Routinely check environmental performance/compliance", > "Routinely inspect your site for problems", > "Monitor feedback on the environmental performance of your > products/services", > "Improve environmental performance of your products/services", > > My question is how do i collect all the results and put it into one > variable? You would collect them in an Array. Put a line like this before the foreach loop: targets = [ ] Then inside the foreach(), you could add to it: targets << t Finally, you can make use of it after the foreach() loop. James Edward Gray II