Skip to content

Commit

Permalink
Update Symbol
Browse files Browse the repository at this point in the history
  • Loading branch information
sampersand committed Jul 14, 2024
1 parent b85cd82 commit a2fc0dd
Show file tree
Hide file tree
Showing 4 changed files with 253 additions and 269 deletions.
6 changes: 3 additions & 3 deletions core/string.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -897,10 +897,10 @@ class String
# number #=> "9"
#
def =~: (Regexp regex) -> Integer?
| [T] (_MatchAgainst[self, T] object) -> T
| [T] (_MatchAgainst[T] object) -> T

interface _MatchAgainst[O, T]
def =~: (O string) -> T
interface _MatchAgainst[T]
def =~: (String string) -> T
end

# <!--
Expand Down
62 changes: 36 additions & 26 deletions core/symbol.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,7 @@ class Symbol
# Symbol.all_symbols.size # => 9334
# Symbol.all_symbols.take(3) # => [:!, :"\"", :"#"]
#
def self.all_symbols: () -> ::Array[Symbol]

public
def self.all_symbols: () -> Array[Symbol]

# <!--
# rdoc-file=string.c
Expand All @@ -152,21 +150,21 @@ class Symbol
#
# Related: String#<=>.
#
def <=>: (Symbol other) -> Integer
| (untyped other) -> Integer?
def <=>: (Symbol object) -> (-1 | 0 | 1)
| (untyped) -> nil

# <!--
# rdoc-file=string.c
# - symbol == object -> true or false
# -->
# Returns `true` if `object` is the same object as `self`, `false` otherwise.
#
def ==: (untyped obj) -> bool
def ==: (untyped object) -> bool

# <!-- rdoc-file=string.c -->
# Returns `true` if `object` is the same object as `self`, `false` otherwise.
#
def ===: (untyped obj) -> bool
alias === ==

# <!--
# rdoc-file=string.c
Expand All @@ -176,7 +174,7 @@ class Symbol
# variables; see String#=~.
#
def =~: (Regexp regex) -> Integer?
| [T] (String::_MatchAgainst[self, T] object) -> T
| [T] (String::_MatchAgainst[T] object) -> T

# <!--
# rdoc-file=string.c
Expand All @@ -188,12 +186,10 @@ class Symbol
# -->
# Equivalent to `symbol.to_s[]`; see String#[].
#
def []: (int index) -> String?
| (int start, int length) -> String?
| (Range[Integer?] range) -> String?
| (Regexp regexp) -> String?
| (Regexp regexp, int | String capture) -> String?
| (String match_str) -> String?
def []: (int start, ?int length) -> String?
| (range[int?] range) -> String?
| (Regexp regexp, ?MatchData::capture backref) -> String?
| (String substring) -> String?

# <!--
# rdoc-file=string.c
Expand Down Expand Up @@ -240,7 +236,8 @@ class Symbol
#
# Related: Symbol#casecmp?, String#casecmp.
#
def casecmp: (untyped other) -> Integer?
def casecmp: (Symbol object) -> (-1 | 0 | 1)?
| (untyped) -> nil

# <!--
# rdoc-file=string.c
Expand Down Expand Up @@ -273,7 +270,8 @@ class Symbol
#
# Related: Symbol#casecmp, String#casecmp?.
#
def casecmp?: (untyped other) -> bool?
def casecmp?: (Symbol object) -> bool?
| (untyped) -> nil

# <!--
# rdoc-file=string.c
Expand Down Expand Up @@ -321,7 +319,7 @@ class Symbol
#
# Related: Symbol#inspect, Symbol#name.
#
def id2name: () -> String
alias id2name to_s

# <!--
# rdoc-file=string.c
Expand All @@ -340,7 +338,7 @@ class Symbol
# - intern()
# -->
#
def intern: () -> Symbol
alias intern to_sym

# <!--
# rdoc-file=string.c
Expand All @@ -358,16 +356,16 @@ class Symbol
# Equivalent to `self.to_s.match`, including possible updates to global
# variables; see String#match.
#
def match: (Regexp | string pattern, ?int pos) -> MatchData?
| (Regexp | string pattern, ?int pos) { (MatchData) -> void } -> untyped
def match: (Regexp | string pattern, ?int offset) -> MatchData?
| [T] (Regexp | string pattern, ?int offset) { (MatchData matchdata) -> T } -> T?

# <!--
# rdoc-file=string.c
# - match?(pattern, offset) -> true or false
# -->
# Equivalent to `sym.to_s.match?`; see String#match.
#
def match?: (Regexp | string pattern, ?int pos) -> bool
def match?: (Regexp | string pattern, ?int offset) -> bool

# <!-- rdoc-file=string.c -->
# Equivalent to `self.to_s.succ.to_sym`:
Expand All @@ -378,6 +376,20 @@ class Symbol
#
def next: () -> Symbol

# <!--
# rdoc-file=string.c
# - name -> string
# -->
# Returns a frozen string representation of `self` (not including the leading
# colon):
#
# :foo.name # => "foo"
# :foo.name.frozen? # => true
#
# Related: Symbol#to_s, Symbol#inspect.
#
def name: () -> String

# <!-- rdoc-file=string.c -->
# Equivalent to `self.to_s.length`; see String#length.
#
Expand All @@ -394,7 +406,7 @@ class Symbol
# -->
# Equivalent to `self.to_s.start_with?`; see String#start_with?.
#
def start_with?: (*string | Regexp prefixes) -> bool
def start_with?: (*Regexp | string prefixes) -> bool

# <!--
# rdoc-file=string.c
Expand Down Expand Up @@ -445,7 +457,7 @@ class Symbol
#
# Related: Symbol#inspect, Symbol#name.
#
alias to_s id2name
def to_s: () -> String

# <!--
# rdoc-file=symbol.rb
Expand All @@ -455,7 +467,7 @@ class Symbol
#
# Related: String#to_sym.
#
alias to_sym intern
def to_sym: () -> self

# <!--
# rdoc-file=string.c
Expand All @@ -469,6 +481,4 @@ class Symbol
| (:ascii | :lithuanian | :turkic) -> Symbol
| (:lithuanian, :turkic) -> Symbol
| (:turkic, :lithuanian) -> Symbol

def clone: (?freeze: true?) -> self
end
2 changes: 1 addition & 1 deletion test/stdlib/String_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ def matcher.=~(rhs)
:world
end

assert_send_type '[T] (String::_MatchAgainst[String, T]) -> T',
assert_send_type '[T] (String::_MatchAgainst[T]) -> T',
'hello', :=~, matcher
end

Expand Down
Loading

0 comments on commit a2fc0dd

Please sign in to comment.