Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion core/comparable.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -167,5 +167,13 @@ interface Comparable::_WithSpaceshipOperator
# If `other` is less than `self`, it returns a positive Integer.
# If no comparison is defined with `other` and `self`, it returns `nil`.
#
def <=>: (untyped other) -> Integer?
def <=>: (untyped other) -> Comparable::_CompareToZero?
end

# This interface indicates a type is comparable against zero.
#
interface Comparable::_CompareToZero
def <: (0) -> boolish

def >: (0) -> boolish
end
8 changes: 7 additions & 1 deletion test/stdlib/Comparable_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,17 @@
class ComparableTest < Test::Unit::TestCase
include TestHelper

class ComparableWithZero
def initialize(value) = @value = value
def <(zero) = @value < zero
def >(zero) = @value > zero
end

class Test
include Comparable

def <=>(other)
rand(2) - 1
ComparableWithZero.new rand(2) - 1
end
end

Expand Down