From: "Martin J. Dürst" Date: 2014-01-10T16:16:13+09:00 Subject: [ruby-core:59679] Re: [ruby-trunk - Feature #7688] Error hiding with rb_rescue() on Comparable#==, #coerce and others On 2014/01/10 7:42, marcandre (Marc-Andre Lafortune) wrote: > > Issue #7688 has been updated by marcandre (Marc-Andre Lafortune). > > > tenderlovemaking (Aaron Patterson) wrote: >> It seems like I would have to implement `==` with >> exactly the same logic as `<=>`, except return nil (to indicate it isn't >> comparable) instead of raise an exception (which is exactly what == does >> before this change). > > Not sure I follow... You don't have to implement `==` at all in your example. > Moreover `==` should not return `nil`, it is `<=>` that should return `nil`. > Neither `==`, `!=` nor `<=>` should ever raise exceptions. I agree with Marc. The negative/0/positive convention of the <=> operator effectively comes from C functions such as strcmp. For such functions, there's no case of two arguments being incomparable (and therefore not equal) because the types are checked at compile time. So we have to extend the three cases of negative/0/positive to four if we want to handle both comparable and incomparable cases. Here's a table of how it may/should work: comparable incomparable neg 0 pos nil < true false false exception? <= true true false exception? == false true false false != true false true true >= false true true exception? > false false true exception? Regards, Martin.