From: Brian Candler Date: 2009-08-24T22:17:24+09:00 Subject: Re: 1.8.7 String#lines keeps new-line chars (say it ain't so in 1.9) Thomas Sawyer wrote: > 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 "] ...except there is no built-in method 'words' so you can't accuse it of being inconsistent :-) Some people would want lines with trailing whitespace stripped as well as terminators. Some people would want leading whitespace stripped too. I don't think you can please everyone, so IMO the most flexible and consistent approach is to give the line complete with its terminator, and let the user apply whatever post-processing they like. > 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. I think StringIO is for when you want to duck-type a File, but with in-RAM backing. ruby is certainly lacking consistency in this area. In ruby 1.9, for example, IO still has #each (meaning #each_line), whereas String doesn't any more. -- Posted via http://www.ruby-forum.com/.