Array Problem, sort Array

# and only one object ; the nature of this object doesn't enter into the
# equation. You just don't need to perform any comparisons to sort an
# array of one element... or zero :
indeed, thanks senault for the enlightenment. i was used to thinking that if my sorting routines passes, then i don't have nil objects in them. i totally missed the sorting algorithm for just one and only one element.
see my previous msg to david too.
kind regards -botp

···

From: F. Senault [mailto:fred@lacave.net] :

Hi --

···

On Fri, 29 Jun 2007, Peña, Botp wrote:

On Behalf Of dblack@wobblini.net:
# hat about:
# class C; end
# [C.new].sort
# ?

or maybe,
[complex_objects].sort

i really avoid threading such complex objects to sort, though things
like that can be handled by sort_by or plain sort{0}.

What i'm concerned at is nil, since it's one of the most common object returned.

But it's a question of whether <=> is defined or not, so C.new is in
exactly the same position as nil. So the question is: if [C.new]
(one-element array) "sorts", why should [nil] not "sort"?

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)

On Behalf Of dblack@wobblini.net
#But it's a question of whether <=> is defined or not, so C.new is in
#exactly the same position as nil. So the question is: if [C.new]
#(one-element array) "sorts", why should [nil] not "sort"?

yes, single elements do return _regardless_. i was used to thinking nil-filled arrays wont sort directly. pls forgive my noise.

in general,
  [anyobject].sort always return [anyobject]
  but
  [anyobject,anyobject].sort may or may not be defined (unless filtered by block)

thanks to everyone for the enlightenment.
kind regards -botp

ps: this may be for a new thread, and i should have asked this a long time ago, but: why no <=> op for nil? so [nil, nil, nil].sort => [nil, nil, nil]