
Issue #21157 has been updated by lpogic (Łukasz Pomietło). nobu (Nobuyoshi Nakada) wrote in #note-4:
I'm not sure what the last example means, maybe incomparable -> true?
Yes, this is a case where objects are incomparable. I'm not sure if `true` is the most appropriate value, but I don't have a better idea at the moment. nobu (Nobuyoshi Nakada) wrote in #note-4:
```ruby array.sort{|a, b| (a.y <=> b.y).nonzero? || b.x <=> a.x} ```
This actually solves the presented problem in a relatively clear way. Until now I was not aware of the existence of `nonzero?`. nobu (Nobuyoshi Nakada) wrote in #note-4:
Or BASIC users? Anyway, `<>` in SQL is a boolean operator and not expected returing ±1.
Sure. I only see the similarity when `<>` is used in logical expressions. ---------------------------------------- Feature #21157: Comparison operator <> https://bugs.ruby-lang.org/issues/21157#change-112118 * Author: lpogic (Łukasz Pomietło) * Status: Open ---------------------------------------- I propose introducing a comparison operator *<>* which would give the following results: ```ruby 1 <> 2 # => -1 2 <> 1 # => 1 1 <> 1 # => false 1 <> "a" # => true ``` With the help of the new operator, complex ordering expressions could be written explicitly. For example: ```ruby Point = Struct.new(:x, :y) array = [Point.new(1, 2), Point.new(6, 4), Point.new(2, 2), Point.new(5, 2)] array.sort{|a, b| a.y <> b.y || b.x <> a.x || 0 } # => [#<struct Point x=5, y=2>, #<struct Point x=2, y=2>, #<struct Point x=1, y=2>, #<struct Point x=6, y=4>] ``` The `<>` notation may look familiar to sql users, where it means 'not equal'. Defined in the form given it will retain this meaning to some extent: ```ruby a = b = 1 a_not_equal_b if a <> b a_equal_b unless a <> b ``` -- https://bugs.ruby-lang.org/