File tree Expand file tree Collapse file tree 2 files changed +16
-2
lines changed
Expand file tree Collapse file tree 2 files changed +16
-2
lines changed Original file line number Diff line number Diff line change @@ -174,5 +174,13 @@ interface Comparable::_WithSpaceshipOperator
174174 # If `other` is less than `self`, it returns a positive Integer.
175175 # If no comparison is defined with `other` and `self`, it returns `nil`.
176176 #
177- def <=> : (untyped other) -> Integer?
177+ def <=> : (untyped other) -> Comparable::_CompareToZero?
178+ end
179+
180+ # This interface indicates a type is comparable against zero.
181+ #
182+ interface Comparable::_CompareToZero
183+ def < : (0) -> boolish
184+
185+ def > : (0) -> boolish
178186end
Original file line number Diff line number Diff line change 33class ComparableTest < Test ::Unit ::TestCase
44 include TestHelper
55
6+ class ComparableWithZero
7+ def initialize ( value ) = @value = value
8+ def <( zero ) = @value < zero
9+ def >( zero ) = @value > zero
10+ end
11+
612 class Test
713 include Comparable
814
915 def <=>( other )
10- rand ( 2 ) - 1
16+ ComparableWithZero . new rand ( 2 ) - 1
1117 end
1218 end
1319
You can’t perform that action at this time.
0 commit comments