Sorting partially ordered objects in 1.7.3 fails

Is this an intended change?

In ruby 1.6.7, Array#sort tolerates unordered objects:

$ ~/ruby/src/ruby-1.6.7/ruby
class C; end
class C1 < C; end
class C2 < C; end
p [C, C1, C2].sort
[C2, C1, C]

In 1.7.3, it doesn’t:

$ ruby
class C; end
class C1 < C; end
class C2 < C; end
p [C, C1, C2].sort
-:4:in sort': undefined method>’ for nil (NoMethodError)
from -:4

Is this an intended change?

Probably this is this

···

Wed Jan 23 02:00:14 2002 Yukihiro Matsumoto <matz@ruby-lang.org>

        * object.c (rb_mod_cmp): should raise ArgumentError if
          inheritance/inclusion relation between two classes/modules is
          not defined. [new]

Guy Decoux

But the relation is indeed defined in Joel’s example, and the exception is not
the same…

···

On Sun, Nov 17, 2002 at 09:50:50PM +0900, ts wrote:

Is this an intended change?

Probably this is this

Wed Jan 23 02:00:14 2002 Yukihiro Matsumoto matz@ruby-lang.org

    * object.c (rb_mod_cmp): should raise ArgumentError if
      inheritance/inclusion relation between two classes/modules is
      not defined. [new]


_ _

__ __ | | ___ _ __ ___ __ _ _ __
'_ \ / | __/ __| '_ _ \ / ` | ’ \
) | (| | |
__ \ | | | | | (| | | | |
.__/ _,
|_|/| || ||_,|| |_|
Running Debian GNU/Linux Sid (unstable)
batsman dot geo at yahoo dot com

Oh, I’ve seen copies [of Linux Journal] around the terminal room at The Labs.
– Dennis Ritchie

* object.c (rb_mod_cmp): should raise ArgumentError if
inheritance/inclusion relation between two classes/modules is
not defined. [new]

But the relation is indeed defined in Joel's example,

pigeon% ruby -ve 'class C;end;class C1 < C;end;class C2 < C;end; p C1 <=> C2'
ruby 1.7.3 (2002-10-29) [i686-linux]
nil
pigeon%

pigeon% /usr/bin/ruby -ve 'class C;end;class C1 < C;end;class C2 < C;end; p C1 <=> C2'
ruby 1.6.8 (2002-11-09) [i686-linux]
1
pigeon%

and the exception is not the same...

Well, ruby send a NoMethodError in this case (nil don't reply to `>')

Guy Decoux

I’m stupid.

batsman@tux-chan:/tmp$ cat t.rb

class C; end
class C1 < C; end
#class C2 < C; end
p [C, C1].sort

batsman@tux-chan:/tmp$ ruby1.7 t.rb
[C1, C]
batsman@tux-chan:/tmp$

···

On Sun, Nov 17, 2002 at 11:51:32PM +0900, Mauricio Fernández wrote:

On Sun, Nov 17, 2002 at 09:50:50PM +0900, ts wrote:

Is this an intended change?

Probably this is this

Wed Jan 23 02:00:14 2002 Yukihiro Matsumoto matz@ruby-lang.org

    * object.c (rb_mod_cmp): should raise ArgumentError if
      inheritance/inclusion relation between two classes/modules is
      not defined. [new]

But the relation is indeed defined in Joel’s example, and the exception is not
the same…


_ _

__ __ | | ___ _ __ ___ __ _ _ __
'_ \ / | __/ __| '_ _ \ / ` | ’ \
) | (| | |
__ \ | | | | | (| | | | |
.__/ _,
|_|/| || ||_,|| |_|
Running Debian GNU/Linux Sid (unstable)
batsman dot geo at yahoo dot com

Linux ext2fs has been stable for a long time, now it’s time to break it
– Linuxkongreß '95 in Berlin

ts wrote:…

Thanks. I thought sort had changed, but of course it is Class#<=>. So an
easy way to do a “tolerant” class sort compatibly with all known rubies is:

[C1,C,C2].sort {|c,d| c<=>d || 1}

==> [C2, C1, C]