From: Trans Date: 2009-08-24T21:45:12+09:00 Subject: Re: 1.8.7 String#lines keeps new-line chars (say it ain't so in 1.9) On Aug 24, 4:50 am, Brian Candler wrote: > Thomas Sawyer wrote: > > On Aug 23, 3:32 am, Brian Candler wrote: > > >> Perhaps most importantly of all, if the newlines were stripped, there > >> would be loss of data and it would be impossible to reconstruct the > >> original file exactly from the members of the lines array (e.g. > >> lines.join), as your example shows nicely. > > > How is there loss of data, when you know what was removed? Just join > > ("\n"). > > "Loss of data" means "you don't get back exactly what you started with". > Taking your example, I believe that you want both "A\nB\nC" and > "A\nB\nC\n" to result in lines ["A","B","C"], so this operation is not > reversible. > > Or did you want "A\nB\nC\n" to result in ["A","B","C",""] ?  That would > surprise me more. Most inputs have terminating newlines on the final > line. Granting that prefect reversibility is a requirement here, then yes the later makes sense. I do not think it surprising. To me returning the newline code with #lines would be like returning the spaces for a method #words. Eg. "show it\nto me".words => ["show ", "it\n", "to ", "me "] I think the broader issue here is the question of whether or not String is intended for use by code-point (ie. low-level character) manipulators, or for higher-level human-oriented textual manipulation. I always thought StringIO was for the former case. But now I am seeing Ruby's String is some sort of hodge-podge mixture of the two. T.