From: Morton Goldberg Date: 2007-07-28T21:08:31+09:00 Subject: Re: How to delete array element and add to previous element On Jul 27, 2007, at 11:39 PM, Al Cholic wrote: > The only line that I have trouble understanding is this one: > if row[0].empty? > > I try to logically think about it. Programming is more of an experimental science than a deductive one. If you have a theory like this, convert it into a code snippet and evaluate it (in irb, for example -- although I would do it in TextMate, but not everybody has that). One of Ruby's strengths is, being an interpreted language, it is very easy to test theories. > Lets say it hits a spill-over line > and it has to process the string "C22,C23,C26,C27". So it chomps > it at > divides it up by tabs, which there are none because the chomp removed > them if there were any. So, now row is a one element array. At this > point I think row[0]="C22,C23,C26,C27" and row[1]=nil, row[2]=nil. > Where is my logic flawed? You are wrong in thinking chomp removes any of the tabs. It only removes trailing end-of-line characters. Try "\t\ta,b,c\n".chomp.split("\t') in irb. You will see it produces ["", "", "a,b,c"] I hope you won't mind if I give you a bit of advice. I think you have reached the point in your Ruby journey where you will greatly benefit from two resources: 1. Programming Ruby, The Pragmatic Programmers Guide, 2nd Edition (aka the pickaxe book) by Dave Thomas 2. The Ruby Way, 2nd Edition, by Hal Fulton > Whats the difference between chomp and strip. I've only been using > strip. I think you will find it very helpful to have the PDF version of the pickaxe book on your computer to consult while you are writing code. It can instantly answer questions like this. I have my copy open on- screen all the time while I'm coding. Regards, Morton