Skip to content
Draft
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
3 changes: 2 additions & 1 deletion core/array.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -1114,7 +1114,7 @@ class Array[unchecked out E] < Object
# Related: see [Methods for Querying](rdoc-ref:Array@Methods+for+Querying).
#
def all?: () -> bool
| (_Pattern[E] pattern) -> bool
| (RBS::Ops::_CaseEqual[E] pattern) -> bool
| () { (E obj) -> boolish } -> bool

# <!--
Expand Down Expand Up @@ -4137,6 +4137,7 @@ interface _Rand
def rand: (::Integer max) -> ::Integer
end

%a{deprecated: Use RBS::Ops::_CaseEqual[T]}
interface Array::_Pattern[T]
def ===: (T) -> bool
end
12 changes: 2 additions & 10 deletions core/comparable.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
# * `max` if <code>(self <=> max) > 0</code>.
# * `self` otherwise.
#
module Comparable : _WithSpaceshipOperator
module Comparable : RBS::Ops::_CaseEqual[untyped, Comparable::_CompareToZero?]
# <!--
# rdoc-file=compar.c
# - self < other -> true or false
Expand Down Expand Up @@ -171,22 +171,14 @@ module Comparable : _WithSpaceshipOperator
| [A] (Range[A]) -> (self | A)
end

# This interface defines the condition for Comparable mixin.
#
%a{deprecated: Use RBS::Ops::_Compare[untyped, Comparable::_CompareToZero?]}
interface Comparable::_WithSpaceshipOperator
# `<=>` operator must return Integer or `nil`.
# If `other` is greater than `self`, it returns a positive Integer.
# If `other` equals to `self`, it returns zero.
# 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) -> Comparable::_CompareToZero?
end

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

def >: (0) -> boolish
end
13 changes: 4 additions & 9 deletions core/enumerable.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -272,11 +272,6 @@
# file, not the number of lines.
#
module Enumerable[unchecked out E] : _Each[E]
%a{private}
interface _Pattern
def ===: (untyped) -> bool
end

# <!--
# rdoc-file=enum.c
# - all? -> true or false
Expand Down Expand Up @@ -319,7 +314,7 @@ module Enumerable[unchecked out E] : _Each[E]
# Related: #any?, #none? #one?.
#
def all?: () -> bool
| (_Pattern) -> bool
| (RBS::Ops::_CaseEqual[untyped]) -> bool
| () { (E) -> boolish } -> bool

# <!--
Expand Down Expand Up @@ -363,7 +358,7 @@ module Enumerable[unchecked out E] : _Each[E]
# Related: #all?, #none?, #one?.
#
def any?: () -> bool
| (_Pattern) -> bool
| (RBS::Ops::_CaseEqual[untyped]) -> bool
| () { (E) -> boolish } -> bool

# <!--
Expand Down Expand Up @@ -1265,7 +1260,7 @@ module Enumerable[unchecked out E] : _Each[E]
# Related: #one?, #all?, #any?.
#
def none?: () -> bool
| (_Pattern) -> bool
| (RBS::Ops::_CaseEqual[untyped]) -> bool
| () { (E) -> boolish } -> bool

# <!--
Expand Down Expand Up @@ -1309,7 +1304,7 @@ module Enumerable[unchecked out E] : _Each[E]
# Related: #none?, #all?, #any?.
#
def one?: () -> bool
| (_Pattern) -> bool
| (RBS::Ops::_CaseEqual[untyped]) -> bool
| () { (E) -> boolish } -> bool

# <!--
Expand Down
9 changes: 4 additions & 5 deletions core/hash.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -486,8 +486,7 @@ class Hash[unchecked out K, unchecked out V]
def to_ary: () -> [ K, V ]
end

# Interface for comparing equality of types.
#
%a{deprecated: Use RBS::Ops::_Equals}
interface _Equals
def ==: (untyped other) -> boolish
end
Expand Down Expand Up @@ -770,7 +769,7 @@ class Hash[unchecked out K, unchecked out V]
#
# Related: see [Methods for Fetching](rdoc-ref:Hash@Methods+for+Fetching).
#
def assoc: (_Equals key) -> [ K, V ]?
def assoc: (RBS::Ops::_Equals key) -> [ K, V ]?

# <!--
# rdoc-file=hash.c
Expand Down Expand Up @@ -1403,7 +1402,7 @@ class Hash[unchecked out K, unchecked out V]
#
# Related: see [Methods for Fetching](rdoc-ref:Hash@Methods+for+Fetching).
#
def key: (_Equals) -> K?
def key: (RBS::Ops::_Equals) -> K?

# <!-- rdoc-file=hash.c -->
# Returns whether `key` is a key in `self`:
Expand Down Expand Up @@ -1556,7 +1555,7 @@ class Hash[unchecked out K, unchecked out V]
#
# Related: see [Methods for Fetching](rdoc-ref:Hash@Methods+for+Fetching).
#
def rassoc: (_Equals value) -> [ K, V ]?
def rassoc: (RBS::Ops::_Equals value) -> [ K, V ]?

# <!--
# rdoc-file=hash.c
Expand Down
3 changes: 2 additions & 1 deletion core/kernel.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -675,10 +675,11 @@ module Kernel : BasicObject
| (int | _ToR rational_like, exception: bool) -> Rational?
| (int | _ToR numer, ?int | _ToR denom, ?exception: true) -> Rational
| (int | _ToR numer, ?int | _ToR denom, exception: bool) -> Rational?
| [T] (Numeric & _RationalDiv[T] numer, Numeric denom, ?exception: bool) -> T
| [T] (Numeric & RBS::Ops::_Divide[Numeric, T] numer, Numeric denom, ?exception: bool) -> T
| [T < Numeric] (T value, 1, ?exception: bool) -> T
| (untyped, ?untyped, ?exception: bool) -> Rational?

%a{deprecated: use RBS::Ops::_Divide[Numeric, T]}
interface _RationalDiv[T]
def /: (Numeric) -> T
end
Expand Down
154 changes: 154 additions & 0 deletions core/rbs/ops.rbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
module RBS
module Ops
# An interface for types implementing the `+` operator
interface _Add[O, R]
# Perform the `+` operation
def +: (O other) -> R
end

# An interface for types implementing the `-` operator
interface _Subtract[O, R]
# Perform the `-` operation
def -: (O other) -> R
end

# An interface for types implementing the `*` operator
interface _Times[O, R]
# Perform the `*` operation
def *: (O other) -> R
end

# An interface for types implementing the `/` operator
interface _Divide[O, R]
# Perform the `/` operation
def /: (O other) -> R
end

# An interface for types implementing the `%` operator
interface _Modulo[O, R]
# Perform the `%` operation
def %: (O other) -> R
end

# An interface for types implementing the `**` operator
interface _Power[O, R]
# Perform the `**` operation
def **: (O other) -> R
end

# An interface for types implementing the `<` operator
interface _LessThan[O, R = bool]
# Perform the `<` operation
def <: (O other) -> R
end

# An interface for types implementing the `>` operator
interface _GreaterThan[O, R = bool]
# Perform the `>` operation
def >: (O other) -> R
end

# An interface for types implementing the `<=` operator
interface _LessThanOrEqual[O, R = bool]
# Perform the `<=` operation
def <=: (O other) -> R
end

# An interface for types implementing the `>=` operator
interface _GreaterThanOrEqual[O, R = bool]
# Perform the `>=` operation
def >=: (O other) -> R
end

# An interface for types implementing the `<=>` operator
interface _Compare[O = untyped, R = (-1 | 0 | 1)?]
# Perform the `<=>` operation
def <=>: (O other) -> R
end

# An interface for types implementing the `&` operator
interface _And[O, R]
# Perform the `&` operation
def &: (O other) -> R
end

# An interface for types implementing the `|` operator
interface _Or[O, R]
# Perform the `|` operation
def |: (O other) -> R
end

# An interface for types implementing the `^` operator
interface _Xor[O, R]
# Perform the `^` operation
def ^: (O other) -> R
end

# An interface for types implementing the `<<` operator
interface _LeftShift[O, R]
# Perform the `<<` operation
def <<: (O other) -> R
end

# An interface for types implementing the `>>` operator
interface _RightShift[O, R]
# Perform the `>>` operation
def >>: (O other) -> R
end

# An interface for types implementing the `~` operator
interface _Not[R]
# Perform the `~` operation
def ~: () -> R
end

# An interface for types implementing the `+@` operator
interface _UnaryPos[R]
# Perform the `+@` operation
def +@: () -> R
end

# An interface for types implementing the `-@` operator
interface _UnaryNeg[R]
# Perform the `-@` operation
def -@: () -> R
end

# An interface for types implementing the `!` operator
interface _LogicalNot[R = bool]
# Perform the `!` operation
def !: () -> R
end

# An interface for types implementing the `==` operator
interface _Equal[O = untyped, R = bool]
# Perform the `==` operation
def ==: (O other) -> R
end

# An interface for types implementing the `===` operator
interface _CaseEqual[O, R = bool]
# Perform the `===` operation
def ===: (O other) -> R
end

# An interface for types implementing the `=~` operator
interface _Matches[O, R]
# Perform the `=~` operation
def =~: (O other) -> R
end

# An interface for types implementing the `!=` operator
interface _NotEqual[O = untyped, R = bool]
# Perform the `!=` operation
def !=: (O other) -> R
end

# An interface for types implementing the `!~` operator
interface _NotMatches[O, R = bool]
# Perform the `!~` operation
def !~: (O other) -> R
end
end
end

3 changes: 2 additions & 1 deletion core/string.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -1302,8 +1302,9 @@ class String
# Related: see [Querying](rdoc-ref:String@Querying).
#
def =~: (Regexp regex) -> Integer?
| [T] (_MatchAgainst[self, T] object) -> T
| [T] (RBS::Ops::_Matches[self, T] object) -> T

%a{deprecated: Use RBS::Ops::_Matches[O, T]}
interface _MatchAgainst[O, T]
def =~: (O string) -> T
end
Expand Down
Loading