From: Al Cholic Date: 2007-07-28T09:08:52+09:00 Subject: Re: How to delete array element and add to previous element > > raw_data = DATA.read > data = [] > recd = nil > raw_data.each do |line| > row = line.chomp.split("\t") > if row[0].empty? > recd[2] << row[2] > else > data << (recd = row) > end > end > p data > > > Regards, Morton Hi Morton, Thank you very much for putting effort into this. I was able to get it working, but could you explain how it works. Here is the way I implemented: def get_component_info(bom) #gettting the bom array (each element=line) data = [] #setting up a temp variable recd = nil bom.each do |line| #starting to loop though each line row = line.chomp.split("\t") #created new array row by splitting with tab if row[0].empty? recd[2] << row[2] else data << (recd = row) end end data end Questions: at this line: if row[0].empty? Why are you checking the first element of the array? Would this always return false because there are no empty lines in the raw text file. at this line: recd[2] << row[2] Does recd now become a an array? And you are storing the third element of row in the third position of recd? Why? at this line: data << (recd = row) Is this the way to read it: assign row value to recd and store it in data? I hope you can clarify these points. It would be big help in understanding ruby better for me. Thank you, Chris -- Posted via http://www.ruby-forum.com/.