[Comparable] Add in Comparable::_CompareToZero#2697
Conversation
|
I believe it should return
https://docs.ruby-lang.org/en/master/Comparable.html Also, I cannot think of any specific problems that this change would solve. |
|
Yeah, the docs are correct—it actually checks the return valeu for While all of the stdlib returns an class Kilometers
include Comparable
def initialize(value) = @value = value.to_f
def to_f = @value
def <=>(other) = @value - other.to_f
# ...
end
p Kilometers.new(1.2) < Kilometers.new(3.4)This doesn't typecheck under the current RBS signatures, but does work in Ruby |
def <=>(other) = @value <=> other.to_fThe point is still valid: |
|
@ParadoxV5 this is actually the way that ruby 0.49 did it: % ./fixed/ruby <<RUBY
class X
include Comparable
def <=>(r) "A" <=> r end
end
print(X.new() <=> "Q")
RUBY
-16 |
soutaro
left a comment
There was a problem hiding this comment.
Let's go with the updated definition.
My only concern is if the (0) -> boolish works correctly with Steep... 😅
This PR adds in the
Comparable::_CompareToZerointerface, which is the actual return type thatComparableexpects<=>to return.