---2049402039-258736838-11830462583351
Content-Type: MULTIPART/MIXED; BOUNDARY="-2049402039-258736838-1183046258=:23351"

  This message is in MIME format.  The first part should be readable text,
  while the remaining parts are likely unreadable without MIME-aware tools.

---2049402039-258736838-11830462583351
Content-Type: TEXT/PLAIN; charset=X-UNKNOWN; format=flowed
Content-Transfer-Encoding: QUOTED-PRINTABLE

Hi --

On Thu, 28 Jun 2007, Pe, Botp wrote:

> # > A little digression for everyone though...
> # >   irb(main):013:0> [nil].sort
> # >   => [nil]
> # >
> # > is that intended?
> #
> # Well, you don't need the comparison operator where there's only one
> # element, do you ?
>
> careful with the "one" there. The array returned may be complex.
> eg,
> irb(main):029:0> [[nil,[nil,"a"]]].sort
> => [[nil, [nil, "a"]]]
> irb(main):030:0> [[nil,[nil,"a"]]].flatten.sort
> NoMethodError: undefined method `<=>' for nil:NilClass
>        from (irb):30:in `sort'
>
> again, as i've said to Phrogz, the behavior hints that nil elements by themselves are sortable. Remember, programs contain blackboxes wc may be complex and not obvious, eg
>   complex_proc_ret_array.sort_complex.foo_proc.bar_proc
>
> one could argue bluntly too, eg
> [nil].sort
> =>[nil]      # yes, there is no need to sort
> [nil,nil].sort
> =>[nil,nil]  # yes, there is no need to sort
>
> I really value consistency of object behavior when it comes to ruby, maybe because it's too dynamic and i want least number of surprises (especiallyhen you chain things).

What about:

   class C; end
   [C.new].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)
---2049402039-258736838-11830462583351--
---2049402039-258736838-11830462583351--