Skip to content

Commit a2fc0dd

Browse files
committed
Update Symbol
1 parent b85cd82 commit a2fc0dd

File tree

4 files changed

+253
-269
lines changed

4 files changed

+253
-269
lines changed

core/string.rbs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -897,10 +897,10 @@ class String
897897
# number #=> "9"
898898
#
899899
def =~: (Regexp regex) -> Integer?
900-
| [T] (_MatchAgainst[self, T] object) -> T
900+
| [T] (_MatchAgainst[T] object) -> T
901901

902-
interface _MatchAgainst[O, T]
903-
def =~: (O string) -> T
902+
interface _MatchAgainst[T]
903+
def =~: (String string) -> T
904904
end
905905

906906
# <!--

core/symbol.rbs

Lines changed: 36 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,7 @@ class Symbol
131131
# Symbol.all_symbols.size # => 9334
132132
# Symbol.all_symbols.take(3) # => [:!, :"\"", :"#"]
133133
#
134-
def self.all_symbols: () -> ::Array[Symbol]
135-
136-
public
134+
def self.all_symbols: () -> Array[Symbol]
137135

138136
# <!--
139137
# rdoc-file=string.c
@@ -152,21 +150,21 @@ class Symbol
152150
#
153151
# Related: String#<=>.
154152
#
155-
def <=>: (Symbol other) -> Integer
156-
| (untyped other) -> Integer?
153+
def <=>: (Symbol object) -> (-1 | 0 | 1)
154+
| (untyped) -> nil
157155

158156
# <!--
159157
# rdoc-file=string.c
160158
# - symbol == object -> true or false
161159
# -->
162160
# Returns `true` if `object` is the same object as `self`, `false` otherwise.
163161
#
164-
def ==: (untyped obj) -> bool
162+
def ==: (untyped object) -> bool
165163

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

171169
# <!--
172170
# rdoc-file=string.c
@@ -176,7 +174,7 @@ class Symbol
176174
# variables; see String#=~.
177175
#
178176
def =~: (Regexp regex) -> Integer?
179-
| [T] (String::_MatchAgainst[self, T] object) -> T
177+
| [T] (String::_MatchAgainst[T] object) -> T
180178

181179
# <!--
182180
# rdoc-file=string.c
@@ -188,12 +186,10 @@ class Symbol
188186
# -->
189187
# Equivalent to `symbol.to_s[]`; see String#[].
190188
#
191-
def []: (int index) -> String?
192-
| (int start, int length) -> String?
193-
| (Range[Integer?] range) -> String?
194-
| (Regexp regexp) -> String?
195-
| (Regexp regexp, int | String capture) -> String?
196-
| (String match_str) -> String?
189+
def []: (int start, ?int length) -> String?
190+
| (range[int?] range) -> String?
191+
| (Regexp regexp, ?MatchData::capture backref) -> String?
192+
| (String substring) -> String?
197193

198194
# <!--
199195
# rdoc-file=string.c
@@ -240,7 +236,8 @@ class Symbol
240236
#
241237
# Related: Symbol#casecmp?, String#casecmp.
242238
#
243-
def casecmp: (untyped other) -> Integer?
239+
def casecmp: (Symbol object) -> (-1 | 0 | 1)?
240+
| (untyped) -> nil
244241

245242
# <!--
246243
# rdoc-file=string.c
@@ -273,7 +270,8 @@ class Symbol
273270
#
274271
# Related: Symbol#casecmp, String#casecmp?.
275272
#
276-
def casecmp?: (untyped other) -> bool?
273+
def casecmp?: (Symbol object) -> bool?
274+
| (untyped) -> nil
277275

278276
# <!--
279277
# rdoc-file=string.c
@@ -321,7 +319,7 @@ class Symbol
321319
#
322320
# Related: Symbol#inspect, Symbol#name.
323321
#
324-
def id2name: () -> String
322+
alias id2name to_s
325323

326324
# <!--
327325
# rdoc-file=string.c
@@ -340,7 +338,7 @@ class Symbol
340338
# - intern()
341339
# -->
342340
#
343-
def intern: () -> Symbol
341+
alias intern to_sym
344342

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

364362
# <!--
365363
# rdoc-file=string.c
366364
# - match?(pattern, offset) -> true or false
367365
# -->
368366
# Equivalent to `sym.to_s.match?`; see String#match.
369367
#
370-
def match?: (Regexp | string pattern, ?int pos) -> bool
368+
def match?: (Regexp | string pattern, ?int offset) -> bool
371369

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

379+
# <!--
380+
# rdoc-file=string.c
381+
# - name -> string
382+
# -->
383+
# Returns a frozen string representation of `self` (not including the leading
384+
# colon):
385+
#
386+
# :foo.name # => "foo"
387+
# :foo.name.frozen? # => true
388+
#
389+
# Related: Symbol#to_s, Symbol#inspect.
390+
#
391+
def name: () -> String
392+
381393
# <!-- rdoc-file=string.c -->
382394
# Equivalent to `self.to_s.length`; see String#length.
383395
#
@@ -394,7 +406,7 @@ class Symbol
394406
# -->
395407
# Equivalent to `self.to_s.start_with?`; see String#start_with?.
396408
#
397-
def start_with?: (*string | Regexp prefixes) -> bool
409+
def start_with?: (*Regexp | string prefixes) -> bool
398410

399411
# <!--
400412
# rdoc-file=string.c
@@ -445,7 +457,7 @@ class Symbol
445457
#
446458
# Related: Symbol#inspect, Symbol#name.
447459
#
448-
alias to_s id2name
460+
def to_s: () -> String
449461

450462
# <!--
451463
# rdoc-file=symbol.rb
@@ -455,7 +467,7 @@ class Symbol
455467
#
456468
# Related: String#to_sym.
457469
#
458-
alias to_sym intern
470+
def to_sym: () -> self
459471

460472
# <!--
461473
# rdoc-file=string.c
@@ -469,6 +481,4 @@ class Symbol
469481
| (:ascii | :lithuanian | :turkic) -> Symbol
470482
| (:lithuanian, :turkic) -> Symbol
471483
| (:turkic, :lithuanian) -> Symbol
472-
473-
def clone: (?freeze: true?) -> self
474484
end

test/stdlib/String_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ def matcher.=~(rhs)
207207
:world
208208
end
209209

210-
assert_send_type '[T] (String::_MatchAgainst[String, T]) -> T',
210+
assert_send_type '[T] (String::_MatchAgainst[T]) -> T',
211211
'hello', :=~, matcher
212212
end
213213

0 commit comments

Comments
 (0)