rbs 3.3.2 → 3.4.0.pre.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/comments.yml +2 -5
- data/.github/workflows/ruby.yml +7 -8
- data/.github/workflows/typecheck.yml +37 -0
- data/CHANGELOG.md +50 -0
- data/Gemfile +1 -1
- data/Gemfile.lock +11 -11
- data/Steepfile +2 -2
- data/core/array.rbs +19 -49
- data/core/basic_object.rbs +2 -2
- data/core/comparable.rbs +17 -8
- data/core/complex.rbs +82 -43
- data/core/data.rbs +2 -4
- data/core/dir.rbs +635 -295
- data/core/enumerable.rbs +11 -18
- data/core/enumerator.rbs +37 -31
- data/core/errors.rbs +4 -0
- data/core/false_class.rbs +34 -15
- data/core/fiber.rbs +23 -0
- data/core/file.rbs +329 -120
- data/core/float.rbs +17 -32
- data/core/gc.rbs +17 -11
- data/core/hash.rbs +22 -44
- data/core/integer.rbs +82 -113
- data/core/io/buffer.rbs +90 -47
- data/core/io.rbs +39 -116
- data/core/kernel.rbs +442 -489
- data/core/match_data.rbs +55 -56
- data/core/module.rbs +45 -1
- data/core/nil_class.rbs +98 -35
- data/core/numeric.rbs +22 -32
- data/core/object_space/weak_key_map.rbs +102 -0
- data/core/process.rbs +1242 -655
- data/core/ractor.rbs +139 -120
- data/core/range.rbs +100 -4
- data/core/rational.rbs +0 -4
- data/core/rbs/unnamed/argf.rbs +16 -8
- data/core/rbs/unnamed/env_class.rbs +0 -24
- data/core/refinement.rbs +8 -0
- data/core/regexp.rbs +1149 -598
- data/core/ruby_vm.rbs +126 -12
- data/core/rubygems/platform.rbs +9 -0
- data/core/rubygems/rubygems.rbs +1 -1
- data/core/rubygems/version.rbs +5 -1
- data/core/set.rbs +20 -22
- data/core/signal.rbs +4 -4
- data/core/string.rbs +283 -230
- data/core/string_io.rbs +2 -14
- data/core/struct.rbs +404 -24
- data/core/symbol.rbs +1 -19
- data/core/thread.rbs +29 -12
- data/core/time.rbs +227 -104
- data/core/trace_point.rbs +2 -5
- data/core/true_class.rbs +54 -21
- data/core/warning.rbs +14 -11
- data/docs/data_and_struct.md +29 -0
- data/docs/syntax.md +3 -5
- data/docs/tools.md +1 -0
- data/ext/rbs_extension/lexer.c +643 -559
- data/ext/rbs_extension/lexer.re +5 -1
- data/ext/rbs_extension/parser.c +12 -3
- data/ext/rbs_extension/unescape.c +7 -47
- data/lib/rbs/cli/diff.rb +4 -1
- data/lib/rbs/cli/validate.rb +280 -0
- data/lib/rbs/cli.rb +2 -194
- data/lib/rbs/collection/config.rb +5 -6
- data/lib/rbs/collection/sources/git.rb +1 -1
- data/lib/rbs/collection.rb +1 -0
- data/lib/rbs/diff.rb +7 -4
- data/lib/rbs/errors.rb +11 -0
- data/lib/rbs/test/errors.rb +4 -1
- data/lib/rbs/test/guaranteed.rb +2 -3
- data/lib/rbs/test/type_check.rb +15 -10
- data/lib/rbs/test.rb +3 -3
- data/lib/rbs/types.rb +29 -0
- data/lib/rbs/unit_test/convertibles.rb +176 -0
- data/lib/rbs/unit_test/spy.rb +136 -0
- data/lib/rbs/unit_test/type_assertions.rb +341 -0
- data/lib/rbs/unit_test/with_aliases.rb +143 -0
- data/lib/rbs/unit_test.rb +6 -0
- data/lib/rbs/version.rb +1 -1
- data/sig/cli/validate.rbs +43 -0
- data/sig/diff.rbs +3 -1
- data/sig/errors.rbs +8 -0
- data/sig/rbs.rbs +1 -1
- data/sig/test/errors.rbs +52 -0
- data/sig/test/guranteed.rbs +9 -0
- data/sig/test/type_check.rbs +19 -0
- data/sig/test.rbs +82 -0
- data/sig/types.rbs +6 -1
- data/sig/unit_test/convertibles.rbs +154 -0
- data/sig/unit_test/spy.rbs +28 -0
- data/sig/unit_test/type_assertions.rbs +194 -0
- data/sig/unit_test/with_aliases.rbs +136 -0
- data/stdlib/base64/0/base64.rbs +307 -45
- data/stdlib/bigdecimal/0/big_decimal.rbs +35 -15
- data/stdlib/coverage/0/coverage.rbs +2 -2
- data/stdlib/csv/0/csv.rbs +25 -55
- data/stdlib/date/0/date.rbs +1 -43
- data/stdlib/date/0/date_time.rbs +1 -13
- data/stdlib/delegate/0/delegator.rbs +186 -0
- data/stdlib/delegate/0/kernel.rbs +47 -0
- data/stdlib/delegate/0/simple_delegator.rbs +98 -0
- data/stdlib/did_you_mean/0/did_you_mean.rbs +1 -1
- data/stdlib/erb/0/erb.rbs +2 -2
- data/stdlib/fileutils/0/fileutils.rbs +0 -19
- data/stdlib/io-console/0/io-console.rbs +12 -1
- data/stdlib/ipaddr/0/ipaddr.rbs +2 -1
- data/stdlib/json/0/json.rbs +320 -81
- data/stdlib/logger/0/logger.rbs +9 -5
- data/stdlib/monitor/0/monitor.rbs +78 -0
- data/stdlib/net-http/0/net-http.rbs +1880 -543
- data/stdlib/objspace/0/objspace.rbs +19 -13
- data/stdlib/openssl/0/openssl.rbs +508 -127
- data/stdlib/optparse/0/optparse.rbs +25 -11
- data/stdlib/pathname/0/pathname.rbs +1 -1
- data/stdlib/pp/0/pp.rbs +2 -5
- data/stdlib/prettyprint/0/prettyprint.rbs +2 -2
- data/stdlib/pstore/0/pstore.rbs +2 -4
- data/stdlib/rdoc/0/comment.rbs +1 -2
- data/stdlib/resolv/0/resolv.rbs +4 -2
- data/stdlib/socket/0/socket.rbs +2 -2
- data/stdlib/socket/0/unix_socket.rbs +2 -2
- data/stdlib/strscan/0/string_scanner.rbs +3 -2
- data/stdlib/tempfile/0/tempfile.rbs +1 -1
- data/stdlib/uri/0/common.rbs +245 -123
- metadata +23 -4
- data/lib/rbs/test/spy.rb +0 -6
data/stdlib/base64/0/base64.rbs
CHANGED
@@ -1,42 +1,215 @@
|
|
1
1
|
# <!-- rdoc-file=lib/base64.rb -->
|
2
|
-
#
|
3
|
-
# #urlsafe_encode64) and decoding (#decode64, #strict_decode64,
|
4
|
-
# #urlsafe_decode64) of binary data using a Base64 representation.
|
2
|
+
# Module Base64 provides methods for:
|
5
3
|
#
|
6
|
-
#
|
4
|
+
# * Encoding a binary string (containing non-ASCII characters) as a string of
|
5
|
+
# printable ASCII characters.
|
6
|
+
# * Decoding such an encoded string.
|
7
7
|
#
|
8
|
-
# A simple encoding and decoding.
|
9
8
|
#
|
10
|
-
#
|
9
|
+
# Base64 is commonly used in contexts where binary data is not allowed or
|
10
|
+
# supported:
|
11
11
|
#
|
12
|
-
#
|
13
|
-
#
|
14
|
-
# plain = Base64.decode64(enc)
|
15
|
-
# # -> "Send reinforcements"
|
12
|
+
# * Images in HTML or CSS files, or in URLs.
|
13
|
+
# * Email attachments.
|
16
14
|
#
|
17
|
-
#
|
18
|
-
#
|
15
|
+
#
|
16
|
+
# A Base64-encoded string is about one-third larger that its source. See the
|
17
|
+
# [Wikipedia article](https://en.wikipedia.org/wiki/Base64) for more
|
18
|
+
# information.
|
19
|
+
#
|
20
|
+
# This module provides three pairs of encode/decode methods. Your choices among
|
21
|
+
# these methods should depend on:
|
22
|
+
#
|
23
|
+
# * Which character set is to be used for encoding and decoding.
|
24
|
+
# * Whether "padding" is to be used.
|
25
|
+
# * Whether encoded strings are to contain newlines.
|
26
|
+
#
|
27
|
+
#
|
28
|
+
# Note: Examples on this page assume that the including program has executed:
|
29
|
+
#
|
30
|
+
# require 'base64'
|
31
|
+
#
|
32
|
+
# ## Encoding Character Sets
|
33
|
+
#
|
34
|
+
# A Base64-encoded string consists only of characters from a 64-character set:
|
35
|
+
#
|
36
|
+
# * `('A'..'Z')`.
|
37
|
+
# * `('a'..'z')`.
|
38
|
+
# * `('0'..'9')`.
|
39
|
+
# * `=`, the 'padding' character.
|
40
|
+
# * Either:
|
41
|
+
# * `%w[+ /]`:
|
42
|
+
# [RFC-2045-compliant](https://datatracker.ietf.org/doc/html/rfc2045);
|
43
|
+
# *not* safe for URLs.
|
44
|
+
# * `%w[- _]`:
|
45
|
+
# [RFC-4648-compliant](https://datatracker.ietf.org/doc/html/rfc4648);
|
46
|
+
# safe for URLs.
|
47
|
+
#
|
48
|
+
#
|
49
|
+
#
|
50
|
+
# If you are working with Base64-encoded strings that will come from or be put
|
51
|
+
# into URLs, you should choose this encoder-decoder pair of RFC-4648-compliant
|
52
|
+
# methods:
|
53
|
+
#
|
54
|
+
# * Base64.urlsafe_encode64 and Base64.urlsafe_decode64.
|
55
|
+
#
|
56
|
+
#
|
57
|
+
# Otherwise, you may choose any of the pairs in this module, including the pair
|
58
|
+
# above, or the RFC-2045-compliant pairs:
|
59
|
+
#
|
60
|
+
# * Base64.encode64 and Base64.decode64.
|
61
|
+
# * Base64.strict_encode64 and Base64.strict_decode64.
|
62
|
+
#
|
63
|
+
#
|
64
|
+
# ## Padding
|
65
|
+
#
|
66
|
+
# Base64-encoding changes a triplet of input bytes into a quartet of output
|
67
|
+
# characters.
|
68
|
+
#
|
69
|
+
# **Padding in Encode Methods**
|
70
|
+
#
|
71
|
+
# Padding -- extending an encoded string with zero, one, or two trailing `=`
|
72
|
+
# characters -- is performed by methods Base64.encode64, Base64.strict_encode64,
|
73
|
+
# and, by default, Base64.urlsafe_encode64:
|
74
|
+
#
|
75
|
+
# Base64.encode64('s') # => "cw==\n"
|
76
|
+
# Base64.strict_encode64('s') # => "cw=="
|
77
|
+
# Base64.urlsafe_encode64('s') # => "cw=="
|
78
|
+
# Base64.urlsafe_encode64('s', padding: false) # => "cw"
|
79
|
+
#
|
80
|
+
# When padding is performed, the encoded string is always of length *4n*, where
|
81
|
+
# `n` is a non-negative integer:
|
82
|
+
#
|
83
|
+
# * Input bytes of length *3n* generate unpadded output characters of length
|
84
|
+
# *4n*:
|
85
|
+
#
|
86
|
+
# # n = 1: 3 bytes => 4 characters.
|
87
|
+
# Base64.strict_encode64('123') # => "MDEy"
|
88
|
+
# # n = 2: 6 bytes => 8 characters.
|
89
|
+
# Base64.strict_encode64('123456') # => "MDEyMzQ1"
|
90
|
+
#
|
91
|
+
# * Input bytes of length *3n+1* generate padded output characters of length
|
92
|
+
# *4(n+1)*, with two padding characters at the end:
|
93
|
+
#
|
94
|
+
# # n = 1: 4 bytes => 8 characters.
|
95
|
+
# Base64.strict_encode64('1234') # => "MDEyMw=="
|
96
|
+
# # n = 2: 7 bytes => 12 characters.
|
97
|
+
# Base64.strict_encode64('1234567') # => "MDEyMzQ1Ng=="
|
98
|
+
#
|
99
|
+
# * Input bytes of length *3n+2* generate padded output characters of length
|
100
|
+
# *4(n+1)*, with one padding character at the end:
|
101
|
+
#
|
102
|
+
# # n = 1: 5 bytes => 8 characters.
|
103
|
+
# Base64.strict_encode64('12345') # => "MDEyMzQ="
|
104
|
+
# # n = 2: 8 bytes => 12 characters.
|
105
|
+
# Base64.strict_encode64('12345678') # => "MDEyMzQ1Njc="
|
106
|
+
#
|
107
|
+
#
|
108
|
+
# When padding is suppressed, for a positive integer *n*:
|
109
|
+
#
|
110
|
+
# * Input bytes of length *3n* generate unpadded output characters of length
|
111
|
+
# *4n*:
|
112
|
+
#
|
113
|
+
# # n = 1: 3 bytes => 4 characters.
|
114
|
+
# Base64.urlsafe_encode64('123', padding: false) # => "MDEy"
|
115
|
+
# # n = 2: 6 bytes => 8 characters.
|
116
|
+
# Base64.urlsafe_encode64('123456', padding: false) # => "MDEyMzQ1"
|
117
|
+
#
|
118
|
+
# * Input bytes of length *3n+1* generate unpadded output characters of length
|
119
|
+
# *4n+2*, with two padding characters at the end:
|
120
|
+
#
|
121
|
+
# # n = 1: 4 bytes => 6 characters.
|
122
|
+
# Base64.urlsafe_encode64('1234', padding: false) # => "MDEyMw"
|
123
|
+
# # n = 2: 7 bytes => 10 characters.
|
124
|
+
# Base64.urlsafe_encode64('1234567', padding: false) # => "MDEyMzQ1Ng"
|
125
|
+
#
|
126
|
+
# * Input bytes of length *3n+2* generate unpadded output characters of length
|
127
|
+
# *4n+3*, with one padding character at the end:
|
128
|
+
#
|
129
|
+
# # n = 1: 5 bytes => 7 characters.
|
130
|
+
# Base64.urlsafe_encode64('12345', padding: false) # => "MDEyMzQ"
|
131
|
+
# # m = 2: 8 bytes => 11 characters.
|
132
|
+
# Base64.urlsafe_encode64('12345678', padding: false) # => "MDEyMzQ1Njc"
|
133
|
+
#
|
134
|
+
#
|
135
|
+
# **Padding in Decode Methods**
|
136
|
+
#
|
137
|
+
# All of the Base64 decode methods support (but do not require) padding.
|
138
|
+
#
|
139
|
+
# Method Base64.decode64 does not check the size of the padding:
|
140
|
+
#
|
141
|
+
# Base64.decode64("MDEyMzQ1Njc") # => "01234567"
|
142
|
+
# Base64.decode64("MDEyMzQ1Njc=") # => "01234567"
|
143
|
+
# Base64.decode64("MDEyMzQ1Njc==") # => "01234567"
|
144
|
+
#
|
145
|
+
# Method Base64.strict_decode64 strictly enforces padding size:
|
146
|
+
#
|
147
|
+
# Base64.strict_decode64("MDEyMzQ1Njc") # Raises ArgumentError
|
148
|
+
# Base64.strict_decode64("MDEyMzQ1Njc=") # => "01234567"
|
149
|
+
# Base64.strict_decode64("MDEyMzQ1Njc==") # Raises ArgumentError
|
150
|
+
#
|
151
|
+
# Method Base64.urlsafe_decode64 allows padding in `str`, which if present, must
|
152
|
+
# be correct: see [Padding](Base64.html#module-Base64-label-Padding), above:
|
153
|
+
#
|
154
|
+
# Base64.urlsafe_decode64("MDEyMzQ1Njc") # => "01234567"
|
155
|
+
# Base64.urlsafe_decode64("MDEyMzQ1Njc=") # => "01234567"
|
156
|
+
# Base64.urlsafe_decode64("MDEyMzQ1Njc==") # Raises ArgumentError.
|
157
|
+
#
|
158
|
+
# ## Newlines
|
159
|
+
#
|
160
|
+
# An encoded string returned by Base64.encode64 or Base64.urlsafe_encode64 has
|
161
|
+
# an embedded newline character after each 60-character sequence, and, if
|
162
|
+
# non-empty, at the end:
|
163
|
+
#
|
164
|
+
# # No newline if empty.
|
165
|
+
# encoded = Base64.encode64("\x00" * 0)
|
166
|
+
# encoded.index("\n") # => nil
|
167
|
+
#
|
168
|
+
# # Newline at end of short output.
|
169
|
+
# encoded = Base64.encode64("\x00" * 1)
|
170
|
+
# encoded.size # => 4
|
171
|
+
# encoded.index("\n") # => 4
|
172
|
+
#
|
173
|
+
# # Newline at end of longer output.
|
174
|
+
# encoded = Base64.encode64("\x00" * 45)
|
175
|
+
# encoded.size # => 60
|
176
|
+
# encoded.index("\n") # => 60
|
177
|
+
#
|
178
|
+
# # Newlines embedded and at end of still longer output.
|
179
|
+
# encoded = Base64.encode64("\x00" * 46)
|
180
|
+
# encoded.size # => 65
|
181
|
+
# encoded.rindex("\n") # => 65
|
182
|
+
# encoded.split("\n").map {|s| s.size } # => [60, 4]
|
183
|
+
#
|
184
|
+
# The string to be encoded may itself contain newlines, which are encoded as
|
185
|
+
# Base64:
|
186
|
+
#
|
187
|
+
# # Base64.encode64("\n\n\n") # => "CgoK\n"
|
188
|
+
# s = "This is line 1\nThis is line 2\n"
|
189
|
+
# Base64.encode64(s) # => "VGhpcyBpcyBsaW5lIDEKVGhpcyBpcyBsaW5lIDIK\n"
|
19
190
|
#
|
20
191
|
module Base64
|
21
192
|
# <!--
|
22
193
|
# rdoc-file=lib/base64.rb
|
23
194
|
# - decode64(str)
|
24
195
|
# -->
|
25
|
-
# Returns
|
26
|
-
#
|
196
|
+
# Returns a string containing the decoding of an RFC-2045-compliant
|
197
|
+
# Base64-encoded string `str`:
|
27
198
|
#
|
28
|
-
#
|
29
|
-
#
|
30
|
-
# 'lzIGxpbmUgdHdvClRoaXMgaXMgbGlu' +
|
31
|
-
# 'ZSB0aHJlZQpBbmQgc28gb24uLi4K'
|
32
|
-
# puts Base64.decode64(str)
|
199
|
+
# s = "VGhpcyBpcyBsaW5lIDEKVGhpcyBpcyBsaW5lIDIK\n"
|
200
|
+
# Base64.decode64(s) # => "This is line 1\nThis is line 2\n"
|
33
201
|
#
|
34
|
-
#
|
202
|
+
# Non-Base64 characters in `str` are ignored; see [Encoding Character
|
203
|
+
# Set](Base64.html#module-Base64-label-Encoding+Character+Sets) above: these
|
204
|
+
# include newline characters and characters `-` and `/`:
|
35
205
|
#
|
36
|
-
#
|
37
|
-
#
|
38
|
-
#
|
39
|
-
#
|
206
|
+
# Base64.decode64("\x00\n-_") # => ""
|
207
|
+
#
|
208
|
+
# Padding in `str` (even if incorrect) is ignored:
|
209
|
+
#
|
210
|
+
# Base64.decode64("MDEyMzQ1Njc") # => "01234567"
|
211
|
+
# Base64.decode64("MDEyMzQ1Njc=") # => "01234567"
|
212
|
+
# Base64.decode64("MDEyMzQ1Njc==") # => "01234567"
|
40
213
|
#
|
41
214
|
def self?.decode64: (String str) -> String
|
42
215
|
|
@@ -44,16 +217,34 @@ module Base64
|
|
44
217
|
# rdoc-file=lib/base64.rb
|
45
218
|
# - encode64(bin)
|
46
219
|
# -->
|
47
|
-
# Returns the Base64-
|
48
|
-
#
|
220
|
+
# Returns a string containing the RFC-2045-compliant Base64-encoding of `bin`.
|
221
|
+
#
|
222
|
+
# Per RFC 2045, the returned string may contain the URL-unsafe characters `+` or
|
223
|
+
# `/`; see [Encoding Character
|
224
|
+
# Set](Base64.html#module-Base64-label-Encoding+Character+Sets) above:
|
225
|
+
#
|
226
|
+
# Base64.encode64("\xFB\xEF\xBE") # => "++++\n"
|
227
|
+
# Base64.encode64("\xFF\xFF\xFF") # => "////\n"
|
228
|
+
#
|
229
|
+
# The returned string may include padding; see
|
230
|
+
# [Padding](Base64.html#module-Base64-label-Padding) above.
|
49
231
|
#
|
50
|
-
#
|
51
|
-
# Base64.encode64("Now is the time for all good coders\nto learn Ruby")
|
232
|
+
# Base64.encode64('*') # => "Kg==\n"
|
52
233
|
#
|
53
|
-
#
|
234
|
+
# The returned string ends with a newline character, and if sufficiently long
|
235
|
+
# will have one or more embedded newline characters; see
|
236
|
+
# [Newlines](Base64.html#module-Base64-label-Newlines) above:
|
54
237
|
#
|
55
|
-
#
|
56
|
-
#
|
238
|
+
# Base64.encode64('*') # => "Kg==\n"
|
239
|
+
# Base64.encode64('*' * 46)
|
240
|
+
# # => "KioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioq\nKg==\n"
|
241
|
+
#
|
242
|
+
# The string to be encoded may itself contain newlines, which will be encoded as
|
243
|
+
# ordinary Base64:
|
244
|
+
#
|
245
|
+
# Base64.encode64("\n\n\n") # => "CgoK\n"
|
246
|
+
# s = "This is line 1\nThis is line 2\n"
|
247
|
+
# Base64.encode64(s) # => "VGhpcyBpcyBsaW5lIDEKVGhpcyBpcyBsaW5lIDIK\n"
|
57
248
|
#
|
58
249
|
def self?.encode64: (String bin) -> String
|
59
250
|
|
@@ -61,9 +252,25 @@ module Base64
|
|
61
252
|
# rdoc-file=lib/base64.rb
|
62
253
|
# - strict_decode64(str)
|
63
254
|
# -->
|
64
|
-
# Returns
|
65
|
-
#
|
66
|
-
#
|
255
|
+
# Returns a string containing the decoding of an RFC-2045-compliant
|
256
|
+
# Base64-encoded string `str`:
|
257
|
+
#
|
258
|
+
# s = "VGhpcyBpcyBsaW5lIDEKVGhpcyBpcyBsaW5lIDIK"
|
259
|
+
# Base64.strict_decode64(s) # => "This is line 1\nThis is line 2\n"
|
260
|
+
#
|
261
|
+
# Non-Base64 characters in `str` not allowed; see [Encoding Character
|
262
|
+
# Set](Base64.html#module-Base64-label-Encoding+Character+Sets) above: these
|
263
|
+
# include newline characters and characters `-` and `/`:
|
264
|
+
#
|
265
|
+
# Base64.strict_decode64("\n") # Raises ArgumentError
|
266
|
+
# Base64.strict_decode64('-') # Raises ArgumentError
|
267
|
+
# Base64.strict_decode64('_') # Raises ArgumentError
|
268
|
+
#
|
269
|
+
# Padding in `str`, if present, must be correct:
|
270
|
+
#
|
271
|
+
# Base64.strict_decode64("MDEyMzQ1Njc") # Raises ArgumentError
|
272
|
+
# Base64.strict_decode64("MDEyMzQ1Njc=") # => "01234567"
|
273
|
+
# Base64.strict_decode64("MDEyMzQ1Njc==") # Raises ArgumentError
|
67
274
|
#
|
68
275
|
def self?.strict_decode64: (String str) -> String
|
69
276
|
|
@@ -71,8 +278,33 @@ module Base64
|
|
71
278
|
# rdoc-file=lib/base64.rb
|
72
279
|
# - strict_encode64(bin)
|
73
280
|
# -->
|
74
|
-
# Returns the Base64-
|
75
|
-
#
|
281
|
+
# Returns a string containing the RFC-2045-compliant Base64-encoding of `bin`.
|
282
|
+
#
|
283
|
+
# Per RFC 2045, the returned string may contain the URL-unsafe characters `+` or
|
284
|
+
# `/`; see [Encoding Character
|
285
|
+
# Set](Base64.html#module-Base64-label-Encoding+Character+Sets) above:
|
286
|
+
#
|
287
|
+
# Base64.strict_encode64("\xFB\xEF\xBE") # => "++++\n"
|
288
|
+
# Base64.strict_encode64("\xFF\xFF\xFF") # => "////\n"
|
289
|
+
#
|
290
|
+
# The returned string may include padding; see
|
291
|
+
# [Padding](Base64.html#module-Base64-label-Padding) above.
|
292
|
+
#
|
293
|
+
# Base64.strict_encode64('*') # => "Kg==\n"
|
294
|
+
#
|
295
|
+
# The returned string will have no newline characters, regardless of its length;
|
296
|
+
# see [Newlines](Base64.html#module-Base64-label-Newlines) above:
|
297
|
+
#
|
298
|
+
# Base64.strict_encode64('*') # => "Kg=="
|
299
|
+
# Base64.strict_encode64('*' * 46)
|
300
|
+
# # => "KioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKg=="
|
301
|
+
#
|
302
|
+
# The string to be encoded may itself contain newlines, which will be encoded as
|
303
|
+
# ordinary Base64:
|
304
|
+
#
|
305
|
+
# Base64.strict_encode64("\n\n\n") # => "CgoK"
|
306
|
+
# s = "This is line 1\nThis is line 2\n"
|
307
|
+
# Base64.strict_encode64(s) # => "VGhpcyBpcyBsaW5lIDEKVGhpcyBpcyBsaW5lIDIK"
|
76
308
|
#
|
77
309
|
def self?.strict_encode64: (String bin) -> String
|
78
310
|
|
@@ -80,12 +312,21 @@ module Base64
|
|
80
312
|
# rdoc-file=lib/base64.rb
|
81
313
|
# - urlsafe_decode64(str)
|
82
314
|
# -->
|
83
|
-
# Returns the
|
84
|
-
#
|
85
|
-
#
|
315
|
+
# Returns the decoding of an RFC-4648-compliant Base64-encoded string `str`:
|
316
|
+
#
|
317
|
+
# `str` may not contain non-Base64 characters; see [Encoding Character
|
318
|
+
# Set](Base64.html#module-Base64-label-Encoding+Character+Sets) above:
|
86
319
|
#
|
87
|
-
#
|
88
|
-
#
|
320
|
+
# Base64.urlsafe_decode64('+') # Raises ArgumentError.
|
321
|
+
# Base64.urlsafe_decode64('/') # Raises ArgumentError.
|
322
|
+
# Base64.urlsafe_decode64("\n") # Raises ArgumentError.
|
323
|
+
#
|
324
|
+
# Padding in `str`, if present, must be correct: see
|
325
|
+
# [Padding](Base64.html#module-Base64-label-Padding), above:
|
326
|
+
#
|
327
|
+
# Base64.urlsafe_decode64("MDEyMzQ1Njc") # => "01234567"
|
328
|
+
# Base64.urlsafe_decode64("MDEyMzQ1Njc=") # => "01234567"
|
329
|
+
# Base64.urlsafe_decode64("MDEyMzQ1Njc==") # Raises ArgumentError.
|
89
330
|
#
|
90
331
|
def self?.urlsafe_decode64: (String str) -> String
|
91
332
|
|
@@ -93,10 +334,31 @@ module Base64
|
|
93
334
|
# rdoc-file=lib/base64.rb
|
94
335
|
# - urlsafe_encode64(bin, padding: true)
|
95
336
|
# -->
|
96
|
-
# Returns the Base64-
|
97
|
-
#
|
98
|
-
#
|
99
|
-
#
|
337
|
+
# Returns the RFC-4648-compliant Base64-encoding of `bin`.
|
338
|
+
#
|
339
|
+
# Per RFC 4648, the returned string will not contain the URL-unsafe characters
|
340
|
+
# `+` or `/`, but instead may contain the URL-safe characters `-` and `_`; see
|
341
|
+
# [Encoding Character
|
342
|
+
# Set](Base64.html#module-Base64-label-Encoding+Character+Sets) above:
|
343
|
+
#
|
344
|
+
# Base64.urlsafe_encode64("\xFB\xEF\xBE") # => "----"
|
345
|
+
# Base64.urlsafe_encode64("\xFF\xFF\xFF") # => "____"
|
346
|
+
#
|
347
|
+
# By default, the returned string may have padding; see
|
348
|
+
# [Padding](Base64.html#module-Base64-label-Padding), above:
|
349
|
+
#
|
350
|
+
# Base64.urlsafe_encode64('*') # => "Kg=="
|
351
|
+
#
|
352
|
+
# Optionally, you can suppress padding:
|
353
|
+
#
|
354
|
+
# Base64.urlsafe_encode64('*', padding: false) # => "Kg"
|
355
|
+
#
|
356
|
+
# The returned string will have no newline characters, regardless of its length;
|
357
|
+
# see [Newlines](Base64.html#module-Base64-label-Newlines) above:
|
358
|
+
#
|
359
|
+
# Base64.urlsafe_encode64('*') # => "Kg=="
|
360
|
+
# Base64.urlsafe_encode64('*' * 46)
|
361
|
+
# # => "KioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKg=="
|
100
362
|
#
|
101
363
|
def self?.urlsafe_encode64: (String bin, ?padding: boolish) -> String
|
102
364
|
end
|
@@ -122,7 +122,23 @@
|
|
122
122
|
# (2/3r).to_d(3) # => 0.667e0
|
123
123
|
# "0.5".to_d # => 0.5e0
|
124
124
|
#
|
125
|
-
# ##
|
125
|
+
# ## Methods for Working with JSON
|
126
|
+
#
|
127
|
+
# * [::json_create](rdoc-ref:BigDecimal.json_create): Returns a new BigDecimal
|
128
|
+
# object constructed from the given object.
|
129
|
+
# * [#as_json](rdoc-ref:BigDecimal#as_json): Returns a 2-element hash
|
130
|
+
# representing `self`.
|
131
|
+
# * [#to_json](rdoc-ref:BigDecimal#to_json): Returns a JSON string
|
132
|
+
# representing `self`.
|
133
|
+
#
|
134
|
+
#
|
135
|
+
# These methods are provided by the [JSON gem](https://github.com/flori/json).
|
136
|
+
# To make these methods available:
|
137
|
+
#
|
138
|
+
# require 'json/add/bigdecimal'
|
139
|
+
#
|
140
|
+
# * ## License
|
141
|
+
#
|
126
142
|
#
|
127
143
|
# Copyright (C) 2002 by Shigeo Kobayashi <shigeo@tinyforest.gr.jp>.
|
128
144
|
#
|
@@ -145,8 +161,12 @@ class BigDecimal < Numeric
|
|
145
161
|
|
146
162
|
# <!--
|
147
163
|
# rdoc-file=ext/bigdecimal/bigdecimal.c
|
148
|
-
# - double_fig
|
164
|
+
# - BigDecimal.double_fig -> integer
|
149
165
|
# -->
|
166
|
+
# Returns the number of digits a Float object is allowed to have; the result is
|
167
|
+
# system-dependent:
|
168
|
+
#
|
169
|
+
# BigDecimal.double_fig # => 16
|
150
170
|
#
|
151
171
|
def self.double_fig: () -> Integer
|
152
172
|
|
@@ -1135,7 +1155,7 @@ class BigDecimal < Numeric
|
|
1135
1155
|
# A space at the start of s returns positive values with a leading space.
|
1136
1156
|
#
|
1137
1157
|
# If s contains a number, a space is inserted after each group of that many
|
1138
|
-
#
|
1158
|
+
# digits, starting from '.' and counting outwards.
|
1139
1159
|
#
|
1140
1160
|
# If s ends with an 'E', engineering notation (0.xxxxEnn) is used.
|
1141
1161
|
#
|
@@ -1143,14 +1163,14 @@ class BigDecimal < Numeric
|
|
1143
1163
|
#
|
1144
1164
|
# Examples:
|
1145
1165
|
#
|
1146
|
-
# BigDecimal('-
|
1147
|
-
# #=> '-123.45678 90123 45678 9'
|
1166
|
+
# BigDecimal('-1234567890123.45678901234567890').to_s('5F')
|
1167
|
+
# #=> '-123 45678 90123.45678 90123 45678 9'
|
1148
1168
|
#
|
1149
|
-
# BigDecimal('
|
1150
|
-
# #=> '+
|
1169
|
+
# BigDecimal('1234567890123.45678901234567890').to_s('+8F')
|
1170
|
+
# #=> '+12345 67890123.45678901 23456789'
|
1151
1171
|
#
|
1152
|
-
# BigDecimal('
|
1153
|
-
# #=> '
|
1172
|
+
# BigDecimal('1234567890123.45678901234567890').to_s(' F')
|
1173
|
+
# #=> ' 1234567890123.4567890123456789'
|
1154
1174
|
#
|
1155
1175
|
def to_s: (?String | int s) -> String
|
1156
1176
|
|
@@ -1383,7 +1403,7 @@ module Kernel
|
|
1383
1403
|
# * Other type:
|
1384
1404
|
#
|
1385
1405
|
# * Raises an exception if keyword argument `exception` is `true`.
|
1386
|
-
# * Returns `nil` if keyword argument `exception` is `
|
1406
|
+
# * Returns `nil` if keyword argument `exception` is `false`.
|
1387
1407
|
#
|
1388
1408
|
#
|
1389
1409
|
#
|
@@ -1406,7 +1426,7 @@ class Integer
|
|
1406
1426
|
#
|
1407
1427
|
# 42.to_d # => 0.42e2
|
1408
1428
|
#
|
1409
|
-
# See also BigDecimal
|
1429
|
+
# See also Kernel.BigDecimal.
|
1410
1430
|
#
|
1411
1431
|
def to_d: () -> BigDecimal
|
1412
1432
|
|
@@ -1498,7 +1518,7 @@ class Float
|
|
1498
1518
|
# 1.234.to_d # => 0.1234e1
|
1499
1519
|
# 1.234.to_d(2) # => 0.12e1
|
1500
1520
|
#
|
1501
|
-
# See also BigDecimal
|
1521
|
+
# See also Kernel.BigDecimal.
|
1502
1522
|
#
|
1503
1523
|
def to_d: (?Integer precision) -> BigDecimal
|
1504
1524
|
|
@@ -1579,7 +1599,7 @@ class String
|
|
1579
1599
|
# "123.45e1".to_d # => 0.12345e4
|
1580
1600
|
# "45.67 degrees".to_d # => 0.4567e2
|
1581
1601
|
#
|
1582
|
-
# See also BigDecimal
|
1602
|
+
# See also Kernel.BigDecimal.
|
1583
1603
|
#
|
1584
1604
|
def to_d: () -> BigDecimal
|
1585
1605
|
end
|
@@ -1600,7 +1620,7 @@ class Rational
|
|
1600
1620
|
#
|
1601
1621
|
# Rational(22, 7).to_d(3) # => 0.314e1
|
1602
1622
|
#
|
1603
|
-
# See also BigDecimal
|
1623
|
+
# See also Kernel.BigDecimal.
|
1604
1624
|
#
|
1605
1625
|
def to_d: (Integer precision) -> BigDecimal
|
1606
1626
|
|
@@ -1685,7 +1705,7 @@ class Complex
|
|
1685
1705
|
# Complex(0.1234567, 0).to_d(4) # => 0.1235e0
|
1686
1706
|
# Complex(Rational(22, 7), 0).to_d(3) # => 0.314e1
|
1687
1707
|
#
|
1688
|
-
# See also BigDecimal
|
1708
|
+
# See also Kernel.BigDecimal.
|
1689
1709
|
#
|
1690
1710
|
def to_d: (*untyped args) -> BigDecimal
|
1691
1711
|
|
@@ -245,8 +245,8 @@ module Coverage
|
|
245
245
|
# -->
|
246
246
|
# Returns true if coverage measurement is supported for the given mode.
|
247
247
|
#
|
248
|
-
# The mode should be one of the following symbols: `:lines`, `:
|
249
|
-
# `:methods`, `:eval`.
|
248
|
+
# The mode should be one of the following symbols: `:lines`, `:oneshot_lines`,
|
249
|
+
# `:branches`, `:methods`, `:eval`.
|
250
250
|
#
|
251
251
|
# Example:
|
252
252
|
#
|