Skip to content
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 Symbol #1930

Merged
merged 3 commits into from
Jul 25, 2024
Merged
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
60 changes: 34 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) -> (-1 | 0 | 1)?

# <!--
# 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[String, T] object) -> T
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Optional] Wondering if you can add a test to confirm the _MatchAgains generic interface works correctly with Steep. (in test/typecheck/_MatchAgainst or somewhere.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have any of these as examples to base it off of?


# <!--
# 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,7 @@ class Symbol
#
# Related: Symbol#casecmp?, String#casecmp.
#
def casecmp: (untyped other) -> Integer?
def casecmp: (untyped object) -> (-1 | 0 | 1)?

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

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

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

# <!--
# rdoc-file=string.c
Expand All @@ -358,16 +354,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 +374,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 +404,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 +455,7 @@ class Symbol
#
# Related: Symbol#inspect, Symbol#name.
#
alias to_s id2name
def to_s: () -> String

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

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

def clone: (?freeze: true?) -> self
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not actually defined in Symbol

end
Loading