From: Logan Capaldo Date: 2007-07-05T22:59:55+09:00 Subject: Re: unintended consequence: string.sort ------=_Part_78341_23063933.1183643997057 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline On 7/5/07, dblack@wobblini.net wrote: > > Hi -- > > On Thu, 5 Jul 2007, Martin DeMello wrote: > > > irb(main):001:0> "hello world".sort > > => ["hello world"] > > > > (Because Enumerable#sort calls to_a, and String#to_a = [string]) > > > > However this is inconsistent with String#each, and almost certainly > > never what the user wants. I'd suggest > > String.split($/).sort.join($/). > > I don't think it's inconsistent with String#each: > > >> "hello world".each {|x| p x } > "hello world" > > If you have multiple lines it will sort that way: > > >> "hello\nworld".sort > => ["hello\n", "world"] Just to continue, String#to_a != [string] either. "a\nb\nc\n".to_a #=> ["a\n", "b\n", "c\n"] David > > -- > * Books: > RAILS ROUTING (new! http://www.awprofessional.com/title/0321509242) > RUBY FOR RAILS (http://www.manning.com/black) > * Ruby/Rails training > & consulting: Ruby Power and Light, LLC (http://www.rubypal.com) > > ------=_Part_78341_23063933.1183643997057--