Hi --

On Thu, 1 Nov 2007, Daniel Waite wrote:

> I was porting a small Python script over to Ruby and realized Ruby does
> not sort strings as I expected it would.
>
> 'cba'.sort # ["cba"]
>
> So I wrote this...
>
> class String
>
>  def sort
>    bytes = Array.new
>    self.each_byte { |byte| bytes << byte }
>    bytes.sort.collect { |byte| byte.chr }.join
>  end
>
> end
>
> 'cba'.sort # "abc"

I wouldn't overwrite a core method like that; you could end up with
some very unexpected results. It's better to give it a different name.


David

-- 
Upcoming training by David A. Black/Ruby Power and Light, LLC:
   * Advancing With Rails, Edison, NJ, November 6-9
   * Advancing With Rails, Berlin, Germany, November 19-22
   * Intro to Rails, London, UK, December 3-6 (by Skills Matter)
See http://www.rubypal.com for details!