rbs 2.0.0 → 2.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/comments.yml +34 -0
- data/.github/workflows/ruby.yml +5 -0
- data/CHANGELOG.md +82 -0
- data/README.md +6 -1
- data/Rakefile +56 -21
- data/core/array.rbs +2866 -1086
- data/core/basic_object.rbs +150 -30
- data/core/binding.rbs +33 -0
- data/core/builtin.rbs +4 -4
- data/core/class.rbs +43 -5
- data/core/comparable.rbs +57 -0
- data/core/complex.rbs +170 -4
- data/core/constants.rbs +51 -0
- data/core/deprecated.rbs +7 -0
- data/core/dir.rbs +305 -20
- data/core/encoding.rbs +1214 -77
- data/core/enumerable.rbs +2173 -234
- data/core/enumerator.rbs +448 -182
- data/core/env.rbs +448 -1
- data/core/errno.rbs +1 -10
- data/core/errors.rbs +152 -2
- data/core/exception.rbs +201 -127
- data/core/false_class.rbs +27 -0
- data/core/fiber.rbs +118 -37
- data/core/fiber_error.rbs +8 -9
- data/core/file.rbs +1060 -142
- data/core/file_test.rbs +287 -32
- data/core/float.rbs +776 -300
- data/core/gc.rbs +185 -34
- data/core/global_variables.rbs +5 -1
- data/core/hash.rbs +1582 -649
- data/core/integer.rbs +974 -204
- data/core/io/buffer.rbs +710 -0
- data/core/io/wait.rbs +29 -8
- data/core/io.rbs +2438 -417
- data/core/kernel.rbs +2319 -318
- data/core/marshal.rbs +37 -2
- data/core/match_data.rbs +123 -6
- data/core/math.rbs +126 -6
- data/core/method.rbs +226 -102
- data/core/module.rbs +421 -45
- data/core/nil_class.rbs +64 -0
- data/core/numeric.rbs +620 -142
- data/core/object.rbs +453 -81
- data/core/object_space.rbs +92 -2
- data/core/proc.rbs +482 -285
- data/core/process.rbs +443 -34
- data/core/ractor.rbs +232 -9
- data/core/random.rbs +151 -52
- data/core/range.rbs +885 -160
- data/core/rational.rbs +122 -6
- data/core/rb_config.rbs +14 -4
- data/core/refinement.rbs +44 -0
- data/core/regexp.rbs +156 -14
- data/core/ruby_vm.rbs +42 -3
- data/core/signal.rbs +78 -39
- data/core/string.rbs +2123 -567
- data/core/string_io.rbs +204 -0
- data/core/struct.rbs +283 -28
- data/core/symbol.rbs +304 -30
- data/core/thread.rbs +1288 -688
- data/core/thread_group.rbs +66 -10
- data/core/time.rbs +643 -217
- data/core/trace_point.rbs +100 -12
- data/core/true_class.rbs +24 -0
- data/core/unbound_method.rbs +73 -7
- data/core/warning.rbs +37 -12
- data/docs/CONTRIBUTING.md +40 -34
- data/docs/stdlib.md +3 -102
- data/docs/syntax.md +54 -11
- data/ext/rbs_extension/extconf.rb +1 -0
- data/ext/rbs_extension/lexer.h +5 -0
- data/ext/rbs_extension/lexstate.c +6 -0
- data/ext/rbs_extension/parser.c +85 -10
- data/ext/rbs_extension/ruby_objs.c +4 -2
- data/ext/rbs_extension/ruby_objs.h +2 -2
- data/goodcheck.yml +0 -11
- data/lib/rbs/annotate/annotations.rb +197 -0
- data/lib/rbs/annotate/formatter.rb +80 -0
- data/lib/rbs/annotate/rdoc_annotator.rb +398 -0
- data/lib/rbs/annotate/rdoc_source.rb +120 -0
- data/lib/rbs/annotate.rb +6 -0
- data/lib/rbs/ast/members.rb +21 -13
- data/lib/rbs/buffer.rb +17 -11
- data/lib/rbs/cli.rb +48 -1
- data/lib/rbs/definition_builder/method_builder.rb +28 -16
- data/lib/rbs/definition_builder.rb +6 -2
- data/lib/rbs/environment.rb +8 -4
- data/lib/rbs/location_aux.rb +12 -0
- data/lib/rbs/namespace.rb +1 -1
- data/lib/rbs/prototype/rb.rb +12 -0
- data/lib/rbs/type_alias_regularity.rb +6 -4
- data/lib/rbs/type_name.rb +1 -1
- data/lib/rbs/types.rb +1 -1
- data/lib/rbs/validator.rb +6 -0
- data/lib/rbs/version.rb +1 -1
- data/lib/rbs/writer.rb +54 -4
- data/lib/rbs.rb +0 -2
- data/schema/typeParam.json +3 -3
- data/sig/annotate/annotations.rbs +102 -0
- data/sig/annotate/formatter.rbs +24 -0
- data/sig/annotate/rdoc_annotater.rbs +82 -0
- data/sig/annotate/rdoc_source.rbs +30 -0
- data/sig/buffer.rbs +6 -2
- data/sig/cli.rbs +2 -0
- data/sig/collection/{collections.rbs → sources.rbs} +0 -0
- data/sig/location.rbs +6 -0
- data/sig/members.rbs +24 -18
- data/sig/method_builder.rbs +5 -4
- data/sig/method_types.rbs +5 -1
- data/sig/polyfill.rbs +78 -0
- data/sig/validator.rbs +3 -1
- data/sig/writer.rbs +79 -2
- data/stdlib/abbrev/0/abbrev.rbs +6 -0
- data/stdlib/abbrev/0/array.rbs +26 -0
- data/stdlib/base64/0/base64.rbs +31 -0
- data/stdlib/benchmark/0/benchmark.rbs +74 -3
- data/stdlib/bigdecimal/0/big_decimal.rbs +614 -165
- data/stdlib/bigdecimal-math/0/big_math.rbs +41 -64
- data/stdlib/cgi/0/core.rbs +649 -21
- data/stdlib/coverage/0/coverage.rbs +164 -2
- data/stdlib/csv/0/csv.rbs +2862 -398
- data/stdlib/date/0/date.rbs +483 -25
- data/stdlib/date/0/date_time.rbs +187 -12
- data/stdlib/dbm/0/dbm.rbs +152 -17
- data/stdlib/digest/0/digest.rbs +146 -0
- data/stdlib/erb/0/erb.rbs +65 -245
- data/stdlib/fiber/0/fiber.rbs +73 -91
- data/stdlib/fileutils/0/fileutils.rbs +301 -1
- data/stdlib/find/0/find.rbs +9 -0
- data/stdlib/forwardable/0/forwardable.rbs +65 -1
- data/stdlib/io-console/0/io-console.rbs +227 -15
- data/stdlib/ipaddr/0/ipaddr.rbs +161 -0
- data/stdlib/json/0/json.rbs +1147 -145
- data/stdlib/logger/0/formatter.rbs +24 -0
- data/stdlib/logger/0/log_device.rbs +64 -0
- data/stdlib/logger/0/logger.rbs +165 -13
- data/stdlib/logger/0/period.rbs +10 -0
- data/stdlib/logger/0/severity.rbs +26 -0
- data/stdlib/monitor/0/monitor.rbs +163 -0
- data/stdlib/mutex_m/0/mutex_m.rbs +35 -6
- data/stdlib/net-http/0/manifest.yaml +1 -0
- data/stdlib/net-http/0/net-http.rbs +1513 -683
- data/stdlib/nkf/0/nkf.rbs +372 -0
- data/stdlib/objspace/0/objspace.rbs +149 -90
- data/stdlib/openssl/0/openssl.rbs +8108 -71
- data/stdlib/optparse/0/optparse.rbs +487 -19
- data/stdlib/pathname/0/pathname.rbs +425 -124
- data/stdlib/prettyprint/0/prettyprint.rbs +120 -99
- data/stdlib/prime/0/integer-extension.rbs +20 -2
- data/stdlib/prime/0/prime.rbs +88 -21
- data/stdlib/pstore/0/pstore.rbs +102 -0
- data/stdlib/pty/0/pty.rbs +64 -14
- data/stdlib/resolv/0/resolv.rbs +420 -31
- data/stdlib/rubygems/0/basic_specification.rbs +4 -1
- data/stdlib/rubygems/0/config_file.rbs +33 -1
- data/stdlib/rubygems/0/dependency_installer.rbs +4 -3
- data/stdlib/rubygems/0/installer.rbs +13 -1
- data/stdlib/rubygems/0/path_support.rbs +4 -1
- data/stdlib/rubygems/0/platform.rbs +5 -1
- data/stdlib/rubygems/0/request_set.rbs +44 -2
- data/stdlib/rubygems/0/requirement.rbs +65 -2
- data/stdlib/rubygems/0/rubygems.rbs +407 -0
- data/stdlib/rubygems/0/source_list.rbs +13 -0
- data/stdlib/rubygems/0/specification.rbs +21 -1
- data/stdlib/rubygems/0/stream_ui.rbs +3 -1
- data/stdlib/rubygems/0/uninstaller.rbs +8 -1
- data/stdlib/rubygems/0/version.rbs +60 -157
- data/stdlib/securerandom/0/securerandom.rbs +44 -0
- data/stdlib/set/0/set.rbs +423 -109
- data/stdlib/shellwords/0/shellwords.rbs +55 -77
- data/stdlib/singleton/0/singleton.rbs +20 -0
- data/stdlib/socket/0/addrinfo.rbs +210 -9
- data/stdlib/socket/0/basic_socket.rbs +103 -11
- data/stdlib/socket/0/ip_socket.rbs +31 -9
- data/stdlib/socket/0/socket.rbs +586 -38
- data/stdlib/socket/0/tcp_server.rbs +22 -2
- data/stdlib/socket/0/tcp_socket.rbs +12 -1
- data/stdlib/socket/0/udp_socket.rbs +25 -2
- data/stdlib/socket/0/unix_server.rbs +22 -2
- data/stdlib/socket/0/unix_socket.rbs +45 -5
- data/stdlib/strscan/0/string_scanner.rbs +210 -9
- data/stdlib/tempfile/0/tempfile.rbs +58 -10
- data/stdlib/time/0/time.rbs +208 -116
- data/stdlib/timeout/0/timeout.rbs +10 -0
- data/stdlib/tmpdir/0/tmpdir.rbs +13 -4
- data/stdlib/tsort/0/cyclic.rbs +1 -0
- data/stdlib/tsort/0/interfaces.rbs +1 -0
- data/stdlib/tsort/0/tsort.rbs +42 -0
- data/stdlib/uri/0/common.rbs +57 -8
- data/stdlib/uri/0/file.rbs +55 -109
- data/stdlib/uri/0/ftp.rbs +6 -3
- data/stdlib/uri/0/generic.rbs +558 -329
- data/stdlib/uri/0/http.rbs +60 -114
- data/stdlib/uri/0/https.rbs +8 -102
- data/stdlib/uri/0/ldap.rbs +143 -137
- data/stdlib/uri/0/ldaps.rbs +8 -102
- data/stdlib/uri/0/mailto.rbs +3 -0
- data/stdlib/uri/0/rfc2396_parser.rbs +66 -26
- data/stdlib/uri/0/ws.rbs +6 -3
- data/stdlib/uri/0/wss.rbs +5 -3
- data/stdlib/yaml/0/dbm.rbs +151 -87
- data/stdlib/yaml/0/store.rbs +6 -0
- data/stdlib/zlib/0/zlib.rbs +90 -31
- metadata +18 -6
- data/lib/rbs/location.rb +0 -221
- data/sig/char_scanner.rbs +0 -9
data/core/symbol.rbs
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
|
-
#
|
|
2
|
-
#
|
|
3
|
-
#
|
|
4
|
-
#
|
|
1
|
+
# <!-- rdoc-file=string.c -->
|
|
2
|
+
# Symbol objects represent named identifiers inside the Ruby interpreter.
|
|
3
|
+
#
|
|
4
|
+
# You can create a Symbol object explicitly with:
|
|
5
|
+
#
|
|
6
|
+
# * A [symbol literal](doc/syntax/literals_rdoc.html#label-Symbol+Literals).
|
|
7
|
+
#
|
|
8
|
+
#
|
|
9
|
+
# The same Symbol object will be created for a given name or string for the
|
|
10
|
+
# duration of a program's execution, regardless of the context or meaning of
|
|
5
11
|
# that name. Thus if `Fred` is a constant in one context, a method in another,
|
|
6
12
|
# and a class in a third, the Symbol `:Fred` will be the same object in all
|
|
7
13
|
# three contexts.
|
|
@@ -22,9 +28,147 @@
|
|
|
22
28
|
# $f2.object_id #=> 2514190
|
|
23
29
|
# $f3.object_id #=> 2514190
|
|
24
30
|
#
|
|
31
|
+
# Constant, method, and variable names are returned as symbols:
|
|
32
|
+
#
|
|
33
|
+
# module One
|
|
34
|
+
# Two = 2
|
|
35
|
+
# def three; 3 end
|
|
36
|
+
# @four = 4
|
|
37
|
+
# @@five = 5
|
|
38
|
+
# $six = 6
|
|
39
|
+
# end
|
|
40
|
+
# seven = 7
|
|
41
|
+
#
|
|
42
|
+
# One.constants
|
|
43
|
+
# # => [:Two]
|
|
44
|
+
# One.instance_methods(true)
|
|
45
|
+
# # => [:three]
|
|
46
|
+
# One.instance_variables
|
|
47
|
+
# # => [:@four]
|
|
48
|
+
# One.class_variables
|
|
49
|
+
# # => [:@@five]
|
|
50
|
+
# global_variables.grep(/six/)
|
|
51
|
+
# # => [:$six]
|
|
52
|
+
# local_variables
|
|
53
|
+
# # => [:seven]
|
|
54
|
+
#
|
|
55
|
+
# Symbol objects are different from String objects in that Symbol objects
|
|
56
|
+
# represent identifiers, while String objects represent text or data.
|
|
57
|
+
#
|
|
58
|
+
# ## What's Here
|
|
59
|
+
#
|
|
60
|
+
# First, what's elsewhere. Class Symbol:
|
|
61
|
+
#
|
|
62
|
+
# * Inherits from [class
|
|
63
|
+
# Object](Object.html#class-Object-label-What-27s+Here).
|
|
64
|
+
# * Includes [module
|
|
65
|
+
# Comparable](Comparable.html#module-Comparable-label-What-27s+Here).
|
|
66
|
+
#
|
|
67
|
+
#
|
|
68
|
+
# Here, class Symbol provides methods that are useful for:
|
|
69
|
+
#
|
|
70
|
+
# * [Querying](#class-Symbol-label-Methods+for+Querying)
|
|
71
|
+
# * [Comparing](#class-Symbol-label-Methods+for+Comparing)
|
|
72
|
+
# * [Converting](#class-Symbol-label-Methods+for+Converting)
|
|
73
|
+
#
|
|
74
|
+
#
|
|
75
|
+
# ### Methods for Querying
|
|
76
|
+
#
|
|
77
|
+
# ::all_symbols
|
|
78
|
+
# : Returns an array of the symbols currently in Ruby's symbol table.
|
|
79
|
+
#
|
|
80
|
+
# [#=~](#method-i-3D~)
|
|
81
|
+
# : Returns the index of the first substring in symbol that matches a
|
|
82
|
+
# given Regexp or other object; returns `nil` if no match is found.
|
|
83
|
+
#
|
|
84
|
+
# #[], #slice
|
|
85
|
+
# : Returns a substring of symbol determined by a given index,
|
|
86
|
+
# start/length, or range, or string.
|
|
87
|
+
#
|
|
88
|
+
# #empty?
|
|
89
|
+
# : Returns `true` if `self.length` is zero; `false` otherwise.
|
|
90
|
+
#
|
|
91
|
+
# #encoding
|
|
92
|
+
# : Returns the Encoding object that represents the encoding of symbol.
|
|
93
|
+
#
|
|
94
|
+
# #end_with?
|
|
95
|
+
# : Returns `true` if symbol ends with any of the given strings.
|
|
96
|
+
#
|
|
97
|
+
# #match
|
|
98
|
+
# : Returns a MatchData object if symbol matches a given Regexp; `nil`
|
|
99
|
+
# otherwise.
|
|
100
|
+
#
|
|
101
|
+
# #match?
|
|
102
|
+
# : Returns `true` if symbol matches a given Regexp; `false` otherwise.
|
|
103
|
+
#
|
|
104
|
+
# #length, #size
|
|
105
|
+
# : Returns the number of characters in symbol.
|
|
106
|
+
#
|
|
107
|
+
# #start_with?
|
|
108
|
+
# : Returns `true` if symbol starts with any of the given strings.
|
|
109
|
+
#
|
|
110
|
+
#
|
|
111
|
+
#
|
|
112
|
+
# ### Methods for Comparing
|
|
113
|
+
#
|
|
114
|
+
# [#<=>](#method-i-3C-3D-3E)
|
|
115
|
+
# : Returns -1, 0, or 1 as a given symbol is smaller than, equal to, or
|
|
116
|
+
# larger than symbol.
|
|
117
|
+
#
|
|
118
|
+
# [#==, #===](#method-i-3D-3D)
|
|
119
|
+
# : Returns `true` if a given symbol has the same content and encoding.
|
|
120
|
+
#
|
|
121
|
+
# #casecmp
|
|
122
|
+
# : Ignoring case, returns -1, 0, or 1 as a given symbol is smaller than,
|
|
123
|
+
# equal to, or larger than symbol.
|
|
124
|
+
#
|
|
125
|
+
# #casecmp?
|
|
126
|
+
# : Returns `true` if symbol is equal to a given symbol after Unicode case
|
|
127
|
+
# folding; `false` otherwise.
|
|
128
|
+
#
|
|
129
|
+
#
|
|
130
|
+
#
|
|
131
|
+
# ### Methods for Converting
|
|
132
|
+
#
|
|
133
|
+
# #capitalize
|
|
134
|
+
# : Returns symbol with the first character upcased and all other
|
|
135
|
+
# characters downcased.
|
|
136
|
+
#
|
|
137
|
+
# #downcase
|
|
138
|
+
# : Returns symbol with all characters downcased.
|
|
139
|
+
#
|
|
140
|
+
# #inspect
|
|
141
|
+
# : Returns the string representation of `self` as a symbol literal.
|
|
142
|
+
#
|
|
143
|
+
# #name
|
|
144
|
+
# : Returns the frozen string corresponding to symbol.
|
|
145
|
+
#
|
|
146
|
+
# #succ, #next
|
|
147
|
+
# : Returns the symbol that is the successor to symbol.
|
|
148
|
+
#
|
|
149
|
+
# #swapcase
|
|
150
|
+
# : Returns symbol with all upcase characters downcased and all downcase
|
|
151
|
+
# characters upcased.
|
|
152
|
+
#
|
|
153
|
+
# #to_proc
|
|
154
|
+
# : Returns a Proc object which responds to the method named by symbol.
|
|
155
|
+
#
|
|
156
|
+
# #to_s, #id2name
|
|
157
|
+
# : Returns the string corresponding to `self`.
|
|
158
|
+
#
|
|
159
|
+
# #to_sym, #intern
|
|
160
|
+
# : Returns `self`.
|
|
161
|
+
#
|
|
162
|
+
# #upcase
|
|
163
|
+
# : Returns symbol with all characters upcased.
|
|
164
|
+
#
|
|
25
165
|
class Symbol
|
|
26
166
|
include Comparable
|
|
27
167
|
|
|
168
|
+
# <!--
|
|
169
|
+
# rdoc-file=string.c
|
|
170
|
+
# - Symbol.all_symbols => array
|
|
171
|
+
# -->
|
|
28
172
|
# Returns an array of all the symbols currently in Ruby's symbol table.
|
|
29
173
|
#
|
|
30
174
|
# Symbol.all_symbols.size #=> 903
|
|
@@ -39,6 +183,10 @@ class Symbol
|
|
|
39
183
|
|
|
40
184
|
public
|
|
41
185
|
|
|
186
|
+
# <!--
|
|
187
|
+
# rdoc-file=string.c
|
|
188
|
+
# - symbol <=> other_symbol -> -1, 0, +1, or nil
|
|
189
|
+
# -->
|
|
42
190
|
# Compares `symbol` with `other_symbol` after calling #to_s on each of the
|
|
43
191
|
# symbols. Returns -1, 0, +1, or `nil` depending on whether `symbol` is less
|
|
44
192
|
# than, equal to, or greater than `other_symbol`.
|
|
@@ -50,18 +198,34 @@ class Symbol
|
|
|
50
198
|
def <=>: (Symbol other) -> Integer
|
|
51
199
|
| (untyped other) -> Integer?
|
|
52
200
|
|
|
201
|
+
# <!--
|
|
202
|
+
# rdoc-file=string.c
|
|
203
|
+
# - sym == obj -> true or false
|
|
204
|
+
# -->
|
|
53
205
|
# Equality---If *sym* and *obj* are exactly the same symbol, returns `true`.
|
|
54
206
|
#
|
|
55
207
|
def ==: (untyped obj) -> bool
|
|
56
208
|
|
|
209
|
+
# <!-- rdoc-file=string.c -->
|
|
57
210
|
# Equality---If *sym* and *obj* are exactly the same symbol, returns `true`.
|
|
58
211
|
#
|
|
59
212
|
def ===: (untyped obj) -> bool
|
|
60
213
|
|
|
214
|
+
# <!--
|
|
215
|
+
# rdoc-file=string.c
|
|
216
|
+
# - sym =~ obj -> integer or nil
|
|
217
|
+
# -->
|
|
61
218
|
# Returns `sym.to_s =~ obj`.
|
|
62
219
|
#
|
|
63
220
|
def =~: (untyped obj) -> Integer?
|
|
64
221
|
|
|
222
|
+
# <!--
|
|
223
|
+
# rdoc-file=string.c
|
|
224
|
+
# - sym[idx] -> char
|
|
225
|
+
# - sym[b, n] -> string
|
|
226
|
+
# - sym.slice(idx) -> char
|
|
227
|
+
# - sym.slice(b, n) -> string
|
|
228
|
+
# -->
|
|
65
229
|
# Returns `sym.to_s[]`.
|
|
66
230
|
#
|
|
67
231
|
def []: (int index) -> String?
|
|
@@ -71,62 +235,107 @@ class Symbol
|
|
|
71
235
|
| (Regexp regexp, int | String capture) -> String?
|
|
72
236
|
| (String match_str) -> String?
|
|
73
237
|
|
|
74
|
-
#
|
|
238
|
+
# <!--
|
|
239
|
+
# rdoc-file=string.c
|
|
240
|
+
# - capitalize(*options) -> symbol
|
|
241
|
+
# -->
|
|
242
|
+
# Equivalent to `sym.to_s.capitalize.to_sym`.
|
|
243
|
+
#
|
|
244
|
+
# See String#capitalize.
|
|
75
245
|
#
|
|
76
246
|
def capitalize: () -> Symbol
|
|
77
247
|
| (:ascii | :lithuanian | :turkic) -> Symbol
|
|
78
248
|
| (:lithuanian, :turkic) -> Symbol
|
|
79
249
|
| (:turkic, :lithuanian) -> Symbol
|
|
80
250
|
|
|
81
|
-
#
|
|
82
|
-
#
|
|
83
|
-
#
|
|
251
|
+
# <!--
|
|
252
|
+
# rdoc-file=string.c
|
|
253
|
+
# - casecmp(other_symbol) -> -1, 0, 1, or nil
|
|
254
|
+
# -->
|
|
255
|
+
# Case-insensitive version of [Symbol#<=>](#method-i-3C-3D-3E):
|
|
84
256
|
#
|
|
85
|
-
# :aBcDeF.casecmp(:abcde)
|
|
86
|
-
# :aBcDeF.casecmp(:abcdef)
|
|
87
|
-
# :aBcDeF.casecmp(:abcdefg)
|
|
88
|
-
# :abcdef.casecmp(:ABCDEF)
|
|
257
|
+
# :aBcDeF.casecmp(:abcde) # => 1
|
|
258
|
+
# :aBcDeF.casecmp(:abcdef) # => 0
|
|
259
|
+
# :aBcDeF.casecmp(:abcdefg) # => -1
|
|
260
|
+
# :abcdef.casecmp(:ABCDEF) # => 0
|
|
89
261
|
#
|
|
90
|
-
# `nil`
|
|
91
|
-
# `other_symbol` is not a symbol
|
|
262
|
+
# Returns `nil` if the two symbols have incompatible encodings, or if
|
|
263
|
+
# `other_symbol` is not a symbol:
|
|
92
264
|
#
|
|
93
|
-
#
|
|
94
|
-
#
|
|
265
|
+
# sym = "\u{e4 f6 fc}".encode("ISO-8859-1").to_sym
|
|
266
|
+
# other_sym = :"\u{c4 d6 dc}"
|
|
267
|
+
# sym.casecmp(other_sym) # => nil
|
|
268
|
+
# :foo.casecmp(2) # => nil
|
|
269
|
+
#
|
|
270
|
+
# Currently, case-insensitivity only works on characters A-Z/a-z, not all of
|
|
271
|
+
# Unicode. This is different from Symbol#casecmp?.
|
|
272
|
+
#
|
|
273
|
+
# Related: Symbol#casecmp?.
|
|
95
274
|
#
|
|
96
275
|
def casecmp: (untyped other) -> Integer?
|
|
97
276
|
|
|
277
|
+
# <!--
|
|
278
|
+
# rdoc-file=string.c
|
|
279
|
+
# - casecmp?(other_symbol) -> true, false, or nil
|
|
280
|
+
# -->
|
|
98
281
|
# Returns `true` if `sym` and `other_symbol` are equal after Unicode case
|
|
99
|
-
# folding, `false` if they are not equal
|
|
282
|
+
# folding, `false` if they are not equal:
|
|
283
|
+
#
|
|
284
|
+
# :aBcDeF.casecmp?(:abcde) # => false
|
|
285
|
+
# :aBcDeF.casecmp?(:abcdef) # => true
|
|
286
|
+
# :aBcDeF.casecmp?(:abcdefg) # => false
|
|
287
|
+
# :abcdef.casecmp?(:ABCDEF) # => true
|
|
288
|
+
# :"\u{e4 f6 fc}".casecmp?(:"\u{c4 d6 dc}") #=> true
|
|
289
|
+
#
|
|
290
|
+
# Returns `nil` if the two symbols have incompatible encodings, or if
|
|
291
|
+
# `other_symbol` is not a symbol:
|
|
100
292
|
#
|
|
101
|
-
#
|
|
102
|
-
# :
|
|
103
|
-
#
|
|
104
|
-
# :
|
|
105
|
-
# :"\u{e4 f6 fc}".casecmp?(:"\u{c4 d6 dc}") #=> true
|
|
293
|
+
# sym = "\u{e4 f6 fc}".encode("ISO-8859-1").to_sym
|
|
294
|
+
# other_sym = :"\u{c4 d6 dc}"
|
|
295
|
+
# sym.casecmp?(other_sym) # => nil
|
|
296
|
+
# :foo.casecmp?(2) # => nil
|
|
106
297
|
#
|
|
107
|
-
#
|
|
108
|
-
# `other_symbol` is not a symbol.
|
|
298
|
+
# See [Case Mapping](doc/case_mapping_rdoc.html).
|
|
109
299
|
#
|
|
110
|
-
#
|
|
111
|
-
# "\u{e4 f6 fc}".encode("ISO-8859-1").to_sym.casecmp?(:"\u{c4 d6 dc}") #=> nil
|
|
300
|
+
# Related: Symbol#casecmp.
|
|
112
301
|
#
|
|
113
302
|
def casecmp?: (untyped other) -> bool?
|
|
114
303
|
|
|
115
|
-
#
|
|
304
|
+
# <!--
|
|
305
|
+
# rdoc-file=string.c
|
|
306
|
+
# - downcase(*options) -> symbol
|
|
307
|
+
# -->
|
|
308
|
+
# Equivalent to `sym.to_s.downcase.to_sym`.
|
|
309
|
+
#
|
|
310
|
+
# See String#downcase.
|
|
311
|
+
#
|
|
312
|
+
# Related: Symbol#upcase.
|
|
116
313
|
#
|
|
117
314
|
def downcase: () -> Symbol
|
|
118
315
|
| (:ascii | :fold | :lithuanian | :turkic) -> Symbol
|
|
119
316
|
| (:lithuanian, :turkic) -> Symbol
|
|
120
317
|
| (:turkic, :lithuanian) -> Symbol
|
|
121
318
|
|
|
319
|
+
# <!--
|
|
320
|
+
# rdoc-file=string.c
|
|
321
|
+
# - sym.empty? -> true or false
|
|
322
|
+
# -->
|
|
122
323
|
# Returns whether *sym* is :"" or not.
|
|
123
324
|
#
|
|
124
325
|
def empty?: () -> bool
|
|
125
326
|
|
|
327
|
+
# <!--
|
|
328
|
+
# rdoc-file=string.c
|
|
329
|
+
# - sym.encoding -> encoding
|
|
330
|
+
# -->
|
|
126
331
|
# Returns the Encoding object that represents the encoding of *sym*.
|
|
127
332
|
#
|
|
128
333
|
def encoding: () -> Encoding
|
|
129
334
|
|
|
335
|
+
# <!--
|
|
336
|
+
# rdoc-file=string.c
|
|
337
|
+
# - sym.end_with?([suffixes]+) -> true or false
|
|
338
|
+
# -->
|
|
130
339
|
# Returns true if `sym` ends with one of the `suffixes` given.
|
|
131
340
|
#
|
|
132
341
|
# :hello.end_with?("ello") #=> true
|
|
@@ -137,49 +346,84 @@ class Symbol
|
|
|
137
346
|
#
|
|
138
347
|
def end_with?: (*string suffixes) -> bool
|
|
139
348
|
|
|
349
|
+
# <!-- rdoc-file=string.c -->
|
|
140
350
|
# Returns the name or string corresponding to *sym*.
|
|
141
351
|
#
|
|
142
352
|
# :fred.id2name #=> "fred"
|
|
143
353
|
# :ginger.to_s #=> "ginger"
|
|
144
354
|
#
|
|
355
|
+
# Note that this string is not frozen (unlike the symbol itself). To get a
|
|
356
|
+
# frozen string, use #name.
|
|
357
|
+
#
|
|
145
358
|
def id2name: () -> String
|
|
146
359
|
|
|
360
|
+
# <!--
|
|
361
|
+
# rdoc-file=string.c
|
|
362
|
+
# - sym.inspect -> string
|
|
363
|
+
# -->
|
|
147
364
|
# Returns the representation of *sym* as a symbol literal.
|
|
148
365
|
#
|
|
149
366
|
# :fred.inspect #=> ":fred"
|
|
150
367
|
#
|
|
151
368
|
def inspect: () -> String
|
|
152
369
|
|
|
370
|
+
# <!--
|
|
371
|
+
# rdoc-file=string.c
|
|
372
|
+
# - sym.to_sym -> sym
|
|
373
|
+
# - sym.intern -> sym
|
|
374
|
+
# -->
|
|
153
375
|
# In general, `to_sym` returns the Symbol corresponding to an object. As *sym*
|
|
154
376
|
# is already a symbol, `self` is returned in this case.
|
|
155
377
|
#
|
|
156
378
|
def intern: () -> Symbol
|
|
157
379
|
|
|
380
|
+
# <!--
|
|
381
|
+
# rdoc-file=string.c
|
|
382
|
+
# - sym.length -> integer
|
|
383
|
+
# - sym.size -> integer
|
|
384
|
+
# -->
|
|
158
385
|
# Same as `sym.to_s.length`.
|
|
159
386
|
#
|
|
160
387
|
def length: () -> Integer
|
|
161
388
|
|
|
389
|
+
# <!--
|
|
390
|
+
# rdoc-file=string.c
|
|
391
|
+
# - sym.match(pattern) -> matchdata or nil
|
|
392
|
+
# - sym.match(pattern, pos) -> matchdata or nil
|
|
393
|
+
# -->
|
|
162
394
|
# Returns `sym.to_s.match`.
|
|
163
395
|
#
|
|
164
396
|
def match: (Regexp | string pattern, ?int pos) -> MatchData?
|
|
165
397
|
| (Regexp | string pattern, ?int pos) { (MatchData) -> void } -> untyped
|
|
166
398
|
|
|
399
|
+
# <!--
|
|
400
|
+
# rdoc-file=string.c
|
|
401
|
+
# - sym.match?(pattern) -> true or false
|
|
402
|
+
# - sym.match?(pattern, pos) -> true or false
|
|
403
|
+
# -->
|
|
167
404
|
# Returns `sym.to_s.match?`.
|
|
168
405
|
#
|
|
169
406
|
def match?: (Regexp | string pattern, ?int pos) -> bool
|
|
170
407
|
|
|
408
|
+
# <!-- rdoc-file=string.c -->
|
|
171
409
|
# Same as `sym.to_s.succ.intern`.
|
|
172
410
|
#
|
|
173
411
|
def next: () -> Symbol
|
|
174
412
|
|
|
413
|
+
# <!-- rdoc-file=string.c -->
|
|
175
414
|
# Same as `sym.to_s.length`.
|
|
176
415
|
#
|
|
177
416
|
alias size length
|
|
178
417
|
|
|
418
|
+
# <!-- rdoc-file=string.c -->
|
|
179
419
|
# Returns `sym.to_s[]`.
|
|
180
420
|
#
|
|
181
|
-
alias slice
|
|
421
|
+
alias slice []
|
|
182
422
|
|
|
423
|
+
# <!--
|
|
424
|
+
# rdoc-file=string.c
|
|
425
|
+
# - sym.start_with?([prefixes]+) -> true or false
|
|
426
|
+
# -->
|
|
183
427
|
# Returns true if `sym` starts with one of the `prefixes` given. Each of the
|
|
184
428
|
# `prefixes` should be a String or a Regexp.
|
|
185
429
|
#
|
|
@@ -189,38 +433,68 @@ class Symbol
|
|
|
189
433
|
# # returns true if one of the prefixes matches.
|
|
190
434
|
# :hello.start_with?("heaven", "hell") #=> true
|
|
191
435
|
# :hello.start_with?("heaven", "paradise") #=> false
|
|
436
|
+
#
|
|
192
437
|
def start_with?: (*string prefixes) -> bool
|
|
193
438
|
|
|
439
|
+
# <!--
|
|
440
|
+
# rdoc-file=string.c
|
|
441
|
+
# - sym.succ
|
|
442
|
+
# -->
|
|
194
443
|
# Same as `sym.to_s.succ.intern`.
|
|
195
444
|
#
|
|
196
445
|
alias succ next
|
|
197
446
|
|
|
198
|
-
#
|
|
447
|
+
# <!--
|
|
448
|
+
# rdoc-file=string.c
|
|
449
|
+
# - swapcase(*options) -> symbol
|
|
450
|
+
# -->
|
|
451
|
+
# Equivalent to `sym.to_s.swapcase.to_sym`.
|
|
452
|
+
#
|
|
453
|
+
# See String#swapcase.
|
|
199
454
|
#
|
|
200
455
|
def swapcase: () -> Symbol
|
|
201
456
|
| (:ascii | :lithuanian | :turkic) -> Symbol
|
|
202
457
|
| (:lithuanian, :turkic) -> Symbol
|
|
203
458
|
| (:turkic, :lithuanian) -> Symbol
|
|
204
459
|
|
|
460
|
+
# <!--
|
|
461
|
+
# rdoc-file=string.c
|
|
462
|
+
# - sym.to_proc
|
|
463
|
+
# -->
|
|
205
464
|
# Returns a *Proc* object which responds to the given method by *sym*.
|
|
206
465
|
#
|
|
207
466
|
# (1..3).collect(&:to_s) #=> ["1", "2", "3"]
|
|
208
467
|
#
|
|
209
468
|
def to_proc: () -> Proc
|
|
210
469
|
|
|
470
|
+
# <!--
|
|
471
|
+
# rdoc-file=string.c
|
|
472
|
+
# - sym.id2name -> string
|
|
473
|
+
# - sym.to_s -> string
|
|
474
|
+
# -->
|
|
211
475
|
# Returns the name or string corresponding to *sym*.
|
|
212
476
|
#
|
|
213
477
|
# :fred.id2name #=> "fred"
|
|
214
478
|
# :ginger.to_s #=> "ginger"
|
|
215
479
|
#
|
|
480
|
+
# Note that this string is not frozen (unlike the symbol itself). To get a
|
|
481
|
+
# frozen string, use #name.
|
|
482
|
+
#
|
|
216
483
|
alias to_s id2name
|
|
217
484
|
|
|
485
|
+
# <!-- rdoc-file=string.c -->
|
|
218
486
|
# In general, `to_sym` returns the Symbol corresponding to an object. As *sym*
|
|
219
487
|
# is already a symbol, `self` is returned in this case.
|
|
220
488
|
#
|
|
221
489
|
alias to_sym intern
|
|
222
490
|
|
|
223
|
-
#
|
|
491
|
+
# <!--
|
|
492
|
+
# rdoc-file=string.c
|
|
493
|
+
# - upcase(*options) -> symbol
|
|
494
|
+
# -->
|
|
495
|
+
# Equivalent to `sym.to_s.upcase.to_sym`.
|
|
496
|
+
#
|
|
497
|
+
# See String#upcase.
|
|
224
498
|
#
|
|
225
499
|
def upcase: () -> Symbol
|
|
226
500
|
| (:ascii | :lithuanian | :turkic) -> Symbol
|