From: Andrea Forlin Date: 2007-07-05T22:56:09+09:00 Subject: Re: unintended consequence: string.sort ------=_Part_59506_17480016.1183643771272 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline This may help U? irb(main):001:0> "hello world".split(/|/).sort => [" ", "d", "e", "h", "l", "l", "l", "o", "o", "r", "w"] 2007/7/5, dblack@wobblini.net : > > 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"] > > > 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_59506_17480016.1183643771272--