From: Trans Date: 2009-08-24T23:27:46+09:00 Subject: Re: 1.8.7 String#lines keeps new-line chars (say it ain't so in 1.9) On Aug 24, 9:17 am, Brian Candler wrote: > 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 :-) ok ;) ...just making an analogy. > 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. Sure, but at that point we are moving into a realm of narrower usecases. I believe the short, more concise method name should go to the most frequent use. I have no definitive statistics, but I'd wager that split("\n") is by far the more common case. Based on that, I'd rather see the current def be called something else, like #newlines or #rawlines. But Ruby is ultimately Matz' baby so maybe his more common use is otherwise. > > 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. Yea, I think that b/c StringIO is an IO first and foremost. So I don't think String should aspire to be like StringIO per se. And StringIO can only be like String insofar as it doesn't interfere with it being an IO. By I may be presuming too much. Appreciate the discussion.