Skip to content

Commit 68f12c2

Browse files
committed
Update Rational
1 parent b85cd82 commit 68f12c2

File tree

4 files changed

+442
-231
lines changed

4 files changed

+442
-231
lines changed

core/numeric.rbs

+65
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,71 @@
160160
# * #step: Invokes the given block with the sequence of specified numbers.
161161
#
162162
class Numeric
163+
interface _Coerce[Other, EquivOther, EquivSelf]
164+
def coerce: (Other rhs) -> [EquivOther, EquivSelf]
165+
end
166+
167+
interface _Add[Other, Return]
168+
def +: (Other other) -> Return
169+
end
170+
171+
interface _Subtract[Other, Return]
172+
def -: (Other other) -> Return
173+
end
174+
175+
interface _Multiply[Other, Return]
176+
def *: (Other other) -> Return
177+
end
178+
179+
interface _Divide[Other, Return]
180+
def /: (Other other) -> Return
181+
end
182+
183+
interface _Modulo[Other, Return]
184+
def %: (Other other) -> Return
185+
end
186+
187+
interface _Power[Other, Return]
188+
def **: (Other other) -> Return
189+
end
190+
191+
interface _Divmod[Other, Whole, Part]
192+
def divmod: (Other other) -> [Whole, Part]
193+
end
194+
195+
interface _Compare[Other]
196+
def <=>: (Other other) -> (-1 | 0 | 1)
197+
| (untyped other) -> (-1 | 0 | 1)?
198+
end
199+
200+
interface _GreaterThan[Other, Return]
201+
def >: (Other other) -> Return
202+
end
203+
204+
interface _GreaterOrEqualTo[Other, Return]
205+
def >=: (Other other) -> Return
206+
end
207+
208+
interface _LessThan[Other, Return]
209+
def <: (Other other) -> Return
210+
end
211+
212+
interface _LessOrEqualTo[Other, Return]
213+
def <=: (Other other) -> Return
214+
end
215+
216+
type round_direction = :up | :down | :even | 'up' | 'down' | 'even' | string | nil
217+
218+
# The interface for the sole optional argument to subclasses of `Numeric`'s `rationalize` function.
219+
interface _Eps
220+
# Get the absolute value of this variable.
221+
#
222+
# Technically, the return value needs to be usable within `<subclass>#-` and `<subclass>#+`, but
223+
# it's a bit specific; if you have a usecase for this please create a PR
224+
def abs: () -> Numeric
225+
end
226+
227+
public
163228
include Comparable
164229

165230
public

0 commit comments

Comments
 (0)