-
Notifications
You must be signed in to change notification settings - Fork 216
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update String
's definitions
#1641
Conversation
|
c1bf764
to
c38ac95
Compare
f695dfc
to
c054b20
Compare
This PR is waiting for #1643 to be merged |
9546cc1
to
9e40388
Compare
21f7bf8
to
3779c4c
Compare
3779c4c
to
99906dd
Compare
core/string.rbs
Outdated
@@ -765,7 +765,7 @@ class String | |||
# | |||
# Otherwise returns `self.dup`, which is not frozen. | |||
# | |||
def +@: () -> (self | instance) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self | instance
type doesn't make much sense.
It will be a String
instance or it's subclass, so self
is good here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you mean? instance
@@ -798,8 +798,7 @@ class String | |||
# | |||
# Related: String#concat, which takes multiple arguments. | |||
# | |||
def <<: (Integer codepoint) -> self | |||
| (string other_string) -> self | |||
def <<: (string | Integer str_or_codepoint) -> self |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Combine the two overloads for the case passing a value of String | Integer
.
(This can be improved with future version of Steep, but currently it doesn't work for this.)
@@ -822,19 +821,9 @@ class String | |||
# 'foo' <=> 'FOO' # => 1 | |||
# 'foo' <=> 1 # => nil | |||
# | |||
def <=>: (string | _Spaceship[self] other) -> (-1 | 0 | 1)? | |||
def <=>: (string) -> (-1 | 0 | 1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As we discussed at Discord?
@@ -1361,8 +1348,8 @@ class String | |||
# Like String#chomp, but modifies `self` in place; returns `nil` if no | |||
# modification made, `self` otherwise. | |||
# | |||
def chomp!: (?string separator) -> self? | |||
| (nil) -> nil | |||
def chomp!: (nil) -> nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the case we pass String?
.
@@ -3436,8 +3415,7 @@ class String | |||
# | |||
# Related: String#unicode_normalize!, String#unicode_normalized?. | |||
# | |||
def unicode_normalize: (?:nfc | :nfd | :nfkc | :nfkd form) -> (self | String) | |||
# NOTE: ^ technically can return `self` if `self.encoding` is ascii. | |||
def unicode_normalize: (?:nfc | :nfd | :nfkc | :nfkd form) -> self |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There may be a case that returns exact String
, not self
?
Also replaced |
aac2d13
to
88405d5
Compare
A tiny followup for #1641’s oopsies
IMPORTANT: The
gsub!
function doesn't have tests (but has been tested manually) because of a bug in the test harnessTest harness updates:
TypeAssertions::RUBY_EXE
addedRUBY_EXE
, which is the path to the ruby interpreter—Ruby's the executable guaranteed to be installed on any system we're testing (eg forKernel#system
)TypeAssertions#pass
: Addedpass
, which is used in a few functions to indicate a test passes without using the type-checking assertions directly.String
updates (bolds are significant changes imo):String#{*,+,==,byteindex,center,concat,include?,{r,}index,{l,r}just,match{,?},{r,}partition,scan,sum,to_i,upto}
: Updated variable namesString#{capitalize{,!},chop!}
: Added a TODO to add a variant for when arbitrary constraints come out.String#{bytes,chars,codepoints}
: Returnsself
in the block variantString#{capitalize,downcase}!
: All variants now returnself?
String#{grapheme_clusters,lines}
: Added the block variantString#{clear,insert,prepend,replace,succ}
: Returnsself
nowString::selector
: an alias forstring
used to indicate methods take a string whose contents have a special meaningString#{count,{delete,squeeze,tr{,_s}}{,!}}
: Now usesString::selector
, updated variable namesString.try_convert
: Added(String) -> String | (_ToStr) -> String | (untyped) -> nil
String#initialize{,_copy}
: Moved to the top of the class;initialize
's return type was updated.String#%
: The variants can be implicitString#{+,-}@
: Returnself | instance
nowString#<<
: Separated variants out for the variable namesString#<=>
: Annotated the previouslyuntyped
variant, nowuntyped
returnsnil
.String#===
: Now an alias forString#==
String#=~
: Added the variant for when theother
is not aRegexp
but defines=~
String#[]{,=}
: Collapsed variants, added implicits, the regexp variants now usesMatchData::capture
String#byteslice
: CollapsedRange
variants, and made implicitString#bytesplice
: Added updates from Ruby 3.3String#casecmp{,?}
: Split outstring
vsuntyped
variants;string
variant incasecmp
variant now returns(-1 | 0 | 1)?
String#chomp
: Separator can now be nilString#chomp!
: Now returnsself?
, andnil
separator always returnsnil
.String#delete_{prefix,suffix}!
: Now returnsself?
notString?
String#each_{byte,char,codepoint,grapheme_cluster,line}
:Enumerator
variant is now first, to be consistent with other core lib definitions.String#encode{,!}
: All keyword args are now exhaustively annotated. The technically correct**untyped
is not supplied.String::_EncodeFallbackAref
: Added for use withString#encode{,!}
String#force_encoding
: Now usesencoding
String#gsub{,!}
: TheHash
variant is now implicit, with a_ToS
value; Enumerator is now above the block variant; !!gsub!
isn't testable because of a bug in the test harness !!String#next{,!}
: Now aliases forString#succ{,!}
String#scrub:
Added?nil
to the block variantString#setbyte
: Now returns second variable, which is now_ToInt
.String#slice!
: Updated variable names, usesMatchData:capture
, added implicits.String#split
: Addednil
value for patternString#sub{,!}
: TheHash
variant is now implicit, with a_ToS
value;self
is now returned in the block formString#to_s
: Now returnsself | String
String#to_str
: An alias forString#to_s
String#to_sym
: An alias forString#intern
String#unicode_normalize
: Can now returnself
, named the variableString#unicode_normalize!
: Always returnsself
, named the variableString#unpack
: Implcits, and added the block variantString#unpack1
: Implcits, added?offset: int
parameter