From: dblack@... Date: 2007-07-05T22:43:29+09:00 Subject: Re: unintended consequence: string.sort 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)