From de86470f379a2599d613e07b145f3a6671f531f0 Mon Sep 17 00:00:00 2001 From: SamW Date: Wed, 22 Nov 2023 12:23:48 -0800 Subject: [PATCH] Add in ::Ops interfaces --- core/ops.rbs | 156 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 156 insertions(+) create mode 100644 core/ops.rbs diff --git a/core/ops.rbs b/core/ops.rbs new file mode 100644 index 0000000000..ab55bdefb1 --- /dev/null +++ b/core/ops.rbs @@ -0,0 +1,156 @@ +# A module that contains the interfaces for all overloadable operators in Ruby. +# +# Even though many of these operators have traditional return types (eg `<` would traditionally +# returns a `bool` or `boolish` value), it's valid Ruby to have them return some other type. As +# such, the return types are all also parameters. +module Ops + # The interface that represents the `+` operator. + interface _Add[Rhs, Ouptut] + # Perform the operation `self + other`, which returns an `Output`. + def +: (Rhs other) -> Output + end + + # The interface that represents the `-` operator. + interface _Sub[Rhs, Ouptut] + # Perform the operation `self - other`, which returns an `Output`. + def -: (Rhs other) -> Output + end + + # The interface that represents the `*` operator. + interface _Mul[Rhs, Ouptut] + # Perform the operation `self * other`, which returns an `Output`. + def *: (Rhs other) -> Output + end + + # The interface that represents the `/` operator. + interface _Div[Rhs, Ouptut] + # Perform the operation `self / other`, which returns an `Output`. + def /: (Rhs other) -> Output + end + + # The interface that represents the `%` operator. + interface _Mod[Rhs, Ouptut] + # Perform the operation `self % other`, which returns an `Output`. + def %: (Rhs other) -> Output + end + + # The interface that represents the `**` operator. + interface _Pow[Rhs, Ouptut] + # Perform the operation `self ** other`, which returns an `Output`. + def **: (Rhs other) -> Output + end + + # The interface that represents the `==` operator. + interface _Equal[Rhs, Ouptut] + # Perform the operation `self == other`, which returns an `Output`. + def ==: (Rhs other) -> Output + end + + # The interface that represents the `!=` operator. + interface _NotEqual[Rhs, Ouptut] + # Perform the operation `self != other`, which returns an `Output`. + def !=: (Rhs other) -> Output + end + + # The interface that represents the `=~` operator. + interface _Match[Rhs, Output] + # Perform the operation `self =~ other`, which returns an `Output`. + def =~: (Rhs rhs) -> Output + end + + # The interface that represents the `!~` operator. + interface _NotMatch[Rhs, Output] + # Perform the operation `self !~ other`, which returns an `Output`. + def !~: (Rhs rhs) -> Output + end + + # The interface that represents the `===` operator. + interface _CaseEqual[Rhs, Output] + # Perform the operation `self === other`, which returns an `Output`. + def ===: (Rhs rhs) -> Output + end + + # The interface that represents the `<` operator. + interface _LessThan[Rhs, Ouptut] + # Perform the operation `self < other`, which returns an `Output`. + def <: (Rhs other) -> Output + end + + # The interface that represents the `>` operator. + interface _GreaterThan[Rhs, Ouptut] + # Perform the operation `self > other`, which returns an `Output`. + def >: (Rhs other) -> Output + end + + # The interface that represents the `<=` operator. + interface _LessEqual[Rhs, Ouptut] + # Perform the operation `self <= other`, which returns an `Output`. + def <=: (Rhs other) -> Output + end + + # The interface that represents the `>=` operator. + interface _GreaterEqual[Rhs, Ouptut] + # Perform the operation `self >= other` which returns an `Output`. + def >=: (Rhs other) -> Output + end + + # The interface that represents the `<=>` operator. + interface _Spaceship[Rhs, Output] + # Perform the operation `self <=> other`, which returns an `Output`. + def <=>: (Rhs other) -> Output + end + + # The interface that represents the `<<` operator. + interface _LeftShift[Rhs, Ouptut] + # Perform the operation `self << other`, which returns an `Output`. + def <<: (Rhs other) -> Output + end + + # The interface that represents the `>>` operator. + interface _RightShift[Rhs, Ouptut] + # Perform the operation `self >> other`, which returns an `Output`. + def >>: (Rhs other) -> Output + end + + # The interface that represents the `&` operator. + interface _BitAnd[Rhs, Ouptut] + # Perform the operation `self & other`, which returns an `Output`. + def &: (Rhs other) -> Output + end + + # The interface that represents the `|` operator. + interface _BitOR[Rhs, Ouptut] + # Perform the operation `self | other`, which returns an `Output`. + def |: (Rhs other) -> Output + end + + # The interface that represents the `^` operator. + interface _BitXor[Rhs, Ouptut] + # Perform the operation `self ^ other`, which returns an `Output`. + def ^: (Rhs other) -> Output + end + + # The interface that represents the `~` operator. + interface _BitNot[Ouptut] + # Perform the operation `~self`, which returns an `Output`. + def ~: () -> Output + end + + # The interface that represents the `!` operator. + interface _LogicalNot[Ouptut] + # Perform the operation `!self`, which returns an `Output`. + def !: () -> Output + end + + # The interface that represents the `-@` operator. + interface _Negate[Ouptut] + # Perform the operation `-self`, which returns an `Output`. + def -@: () -> Output + end + + # The interface that represents the `+@` operator. + interface _UnaryPlus[Ouptut] + # Perform the operation `+self`, which returns an `Output`. + def +@: () -> Output + end +end