From: 7stud -- Date: 2009-08-23T17:44:30+09:00 Subject: Re: 1.8.7 String#lines keeps new-line chars (say it ain't so Thomas Sawyer wrote: > Ruby 1.8.7 p72 > > >> "A\nB\nC".lines.to_a > => ["A\n", "B\n", "C"] > > Please, tell me that's a mishap, and not how 1.9 works. I'd expect: > > >> "A\nB\nC".lines.to_a > => ["A", "B", "C"] > > Thanks. $ ruby19 r1test.rb ["A\n", "B\n", "C\n"] $ ri19 String#lines ----------------------------------------------------------- String#lines str.lines(separator=$/) => anEnumerator str.lines(separator=$/) {|substr| block } => str From Ruby 1.9.1 ------------------------------------------------------------------------ Returns an enumerator that gives each line in the string. If a block is given, it iterates over each line in the string. "foo\nbar\n".lines.to_a #=> ["foo\n", "bar\n"] "foo\nb ar".lines.sort #=> ["b ar", "foo\n"] -- Posted via http://www.ruby-forum.com/.