On Jul 27, 2007, at 8:08 PM, Al Cholic wrote: > def get_component_info(bom) #getting 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. row = line.chomp.split("\t") transforms one line of bom from a tab delimited record into an array of fields. row[0] holds the contents of the first field. If that content is an empty string, code will assume the line being processed is a spill-over line. If it is not empty, code will assume the beginning of a new record. > 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 point, code assumes row is a spill-over and that the third field, row[2], is where the spill-over data lives. This line of code appends the spill-over data to the third field, recd[2], of the current record. Here the << operator is a string append. > at this line: > data << (recd = row) > > Is this the way to read it: assign row value to recd and store it in > data? At this point, code assumes it has a new record. The code here is shorthand for recd = row data << recd The first code line above provides a way to reference this record later, should there be spill-over lines following it. The second code line adds (appends) the new record to the array of records the method is building. Here the << operator is an array append. > I hope you can clarify these points. It would be big help in > understanding ruby better for me. I hope I have clarified things sufficiently, but if I haven't, feel free to ask more. Regards, Morton