steep 0.14.0 → 0.15.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (190) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +5 -0
  3. data/exe/rbs +1 -1
  4. data/lib/steep/annotation_parser.rb +4 -4
  5. data/lib/steep/ast/buffer.rb +11 -7
  6. data/lib/steep/ast/builtin.rb +8 -0
  7. data/lib/steep/ast/types/factory.rb +55 -55
  8. data/lib/steep/drivers/check.rb +20 -4
  9. data/lib/steep/drivers/langserver.rb +6 -1
  10. data/lib/steep/drivers/vendor.rb +2 -2
  11. data/lib/steep/project/completion_provider.rb +5 -11
  12. data/lib/steep/project/dsl.rb +14 -0
  13. data/lib/steep/project/file.rb +42 -46
  14. data/lib/steep/project/hover_content.rb +11 -5
  15. data/lib/steep/project/options.rb +25 -3
  16. data/lib/steep/project/target.rb +10 -4
  17. data/lib/steep/signature/errors.rb +1 -1
  18. data/lib/steep/signature/validator.rb +8 -8
  19. data/lib/steep/source.rb +1 -1
  20. data/lib/steep/type_construction.rb +987 -711
  21. data/lib/steep/type_inference/constant_env.rb +1 -1
  22. data/lib/steep/type_inference/context.rb +7 -3
  23. data/lib/steep/type_inference/context_array.rb +111 -0
  24. data/lib/steep/type_inference/local_variable_type_env.rb +226 -0
  25. data/lib/steep/type_inference/logic.rb +130 -0
  26. data/lib/steep/type_inference/type_env.rb +5 -69
  27. data/lib/steep/typing.rb +79 -22
  28. data/lib/steep/version.rb +1 -1
  29. data/lib/steep.rb +6 -1
  30. data/smoke/alias/Steepfile +1 -0
  31. data/smoke/and/Steepfile +1 -0
  32. data/smoke/array/Steepfile +1 -0
  33. data/smoke/array/b.rb +0 -2
  34. data/smoke/block/Steepfile +1 -0
  35. data/smoke/case/Steepfile +1 -0
  36. data/smoke/class/Steepfile +1 -0
  37. data/smoke/const/Steepfile +1 -0
  38. data/smoke/dstr/Steepfile +1 -0
  39. data/smoke/ensure/Steepfile +1 -0
  40. data/smoke/enumerator/Steepfile +1 -0
  41. data/smoke/extension/Steepfile +1 -0
  42. data/smoke/extension/c.rb +1 -0
  43. data/smoke/hash/Steepfile +1 -0
  44. data/smoke/hello/Steepfile +1 -0
  45. data/smoke/if/Steepfile +1 -0
  46. data/smoke/if/a.rb +1 -1
  47. data/smoke/implements/Steepfile +1 -0
  48. data/smoke/initialize/Steepfile +1 -0
  49. data/smoke/integer/Steepfile +1 -0
  50. data/smoke/interface/Steepfile +1 -0
  51. data/smoke/kwbegin/Steepfile +1 -0
  52. data/smoke/lambda/Steepfile +1 -0
  53. data/smoke/literal/Steepfile +1 -0
  54. data/smoke/map/Steepfile +1 -0
  55. data/smoke/method/Steepfile +1 -0
  56. data/smoke/module/Steepfile +1 -0
  57. data/smoke/regexp/Steepfile +1 -0
  58. data/smoke/regression/Steepfile +1 -0
  59. data/smoke/rescue/Steepfile +1 -0
  60. data/smoke/rescue/a.rb +1 -1
  61. data/smoke/self/Steepfile +1 -0
  62. data/smoke/skip/Steepfile +1 -0
  63. data/smoke/stdout/Steepfile +1 -0
  64. data/smoke/super/Steepfile +1 -0
  65. data/smoke/type_case/Steepfile +1 -0
  66. data/smoke/yield/Steepfile +1 -0
  67. data/steep.gemspec +1 -1
  68. data/vendor/ruby-signature/.gitignore +2 -2
  69. data/vendor/ruby-signature/README.md +2 -2
  70. data/vendor/ruby-signature/Rakefile +2 -2
  71. data/vendor/ruby-signature/bin/annotate-with-rdoc +14 -13
  72. data/vendor/ruby-signature/bin/console +1 -1
  73. data/vendor/ruby-signature/bin/sort +7 -6
  74. data/vendor/ruby-signature/bin/test_runner.rb +0 -1
  75. data/vendor/ruby-signature/docs/CONTRIBUTING.md +1 -1
  76. data/vendor/ruby-signature/docs/sigs.md +3 -3
  77. data/vendor/ruby-signature/docs/stdlib.md +1 -1
  78. data/vendor/ruby-signature/docs/syntax.md +9 -9
  79. data/vendor/ruby-signature/exe/rbs +5 -1
  80. data/vendor/ruby-signature/lib/rbs/ast/annotation.rb +27 -0
  81. data/vendor/ruby-signature/lib/rbs/ast/comment.rb +27 -0
  82. data/vendor/ruby-signature/lib/rbs/ast/declarations.rb +395 -0
  83. data/vendor/ruby-signature/lib/rbs/ast/members.rb +362 -0
  84. data/vendor/ruby-signature/lib/rbs/buffer.rb +50 -0
  85. data/vendor/ruby-signature/lib/rbs/builtin_names.rb +55 -0
  86. data/vendor/ruby-signature/lib/rbs/cli.rb +558 -0
  87. data/vendor/ruby-signature/lib/rbs/constant.rb +26 -0
  88. data/vendor/ruby-signature/lib/rbs/constant_table.rb +150 -0
  89. data/vendor/ruby-signature/lib/rbs/definition.rb +170 -0
  90. data/vendor/ruby-signature/lib/rbs/definition_builder.rb +919 -0
  91. data/vendor/ruby-signature/lib/rbs/environment.rb +281 -0
  92. data/vendor/ruby-signature/lib/rbs/environment_loader.rb +136 -0
  93. data/vendor/ruby-signature/lib/rbs/environment_walker.rb +124 -0
  94. data/vendor/ruby-signature/lib/rbs/errors.rb +187 -0
  95. data/vendor/ruby-signature/lib/rbs/location.rb +102 -0
  96. data/vendor/ruby-signature/lib/rbs/method_type.rb +123 -0
  97. data/vendor/ruby-signature/lib/rbs/namespace.rb +91 -0
  98. data/vendor/ruby-signature/lib/{ruby/signature → rbs}/parser.rb +21 -23
  99. data/vendor/ruby-signature/lib/{ruby/signature → rbs}/parser.y +18 -18
  100. data/vendor/ruby-signature/lib/rbs/prototype/rb.rb +553 -0
  101. data/vendor/ruby-signature/lib/rbs/prototype/rbi.rb +587 -0
  102. data/vendor/ruby-signature/lib/rbs/prototype/runtime.rb +381 -0
  103. data/vendor/ruby-signature/lib/rbs/substitution.rb +46 -0
  104. data/vendor/ruby-signature/lib/rbs/test/errors.rb +61 -0
  105. data/vendor/ruby-signature/lib/rbs/test/hook.rb +294 -0
  106. data/vendor/ruby-signature/lib/{ruby/signature → rbs}/test/setup.rb +7 -7
  107. data/vendor/ruby-signature/lib/rbs/test/spy.rb +325 -0
  108. data/vendor/ruby-signature/lib/rbs/test/test_helper.rb +183 -0
  109. data/vendor/ruby-signature/lib/rbs/test/type_check.rb +254 -0
  110. data/vendor/ruby-signature/lib/rbs/test.rb +26 -0
  111. data/vendor/ruby-signature/lib/rbs/type_name.rb +70 -0
  112. data/vendor/ruby-signature/lib/rbs/types.rb +936 -0
  113. data/vendor/ruby-signature/lib/rbs/variance_calculator.rb +138 -0
  114. data/vendor/ruby-signature/lib/rbs/vendorer.rb +47 -0
  115. data/vendor/ruby-signature/lib/rbs/version.rb +3 -0
  116. data/vendor/ruby-signature/lib/rbs/writer.rb +269 -0
  117. data/vendor/ruby-signature/lib/rbs.rb +64 -0
  118. data/vendor/ruby-signature/lib/ruby/signature.rb +4 -61
  119. data/vendor/ruby-signature/{ruby-signature.gemspec → rbs.gemspec} +4 -4
  120. data/vendor/ruby-signature/stdlib/abbrev/abbrev.rbs +58 -1
  121. data/vendor/ruby-signature/stdlib/base64/base64.rbs +69 -13
  122. data/vendor/ruby-signature/stdlib/benchmark/benchmark.rbs +372 -0
  123. data/vendor/ruby-signature/stdlib/builtin/builtin.rbs +9 -0
  124. data/vendor/ruby-signature/stdlib/builtin/dir.rbs +1 -7
  125. data/vendor/ruby-signature/stdlib/builtin/encoding.rbs +2 -1
  126. data/vendor/ruby-signature/stdlib/builtin/exception.rbs +3 -2
  127. data/vendor/ruby-signature/stdlib/builtin/file.rbs +902 -302
  128. data/vendor/ruby-signature/stdlib/builtin/gc.rbs +190 -68
  129. data/vendor/ruby-signature/stdlib/builtin/integer.rbs +3 -6
  130. data/vendor/ruby-signature/stdlib/builtin/kernel.rbs +6 -4
  131. data/vendor/ruby-signature/stdlib/builtin/marshal.rbs +146 -120
  132. data/vendor/ruby-signature/stdlib/builtin/math.rbs +310 -7
  133. data/vendor/ruby-signature/stdlib/builtin/method.rbs +11 -8
  134. data/vendor/ruby-signature/stdlib/builtin/module.rbs +959 -103
  135. data/vendor/ruby-signature/stdlib/builtin/proc.rbs +3 -0
  136. data/vendor/ruby-signature/stdlib/builtin/process.rbs +981 -108
  137. data/vendor/ruby-signature/stdlib/builtin/random.rbs +215 -41
  138. data/vendor/ruby-signature/stdlib/builtin/rb_config.rbs +47 -0
  139. data/vendor/ruby-signature/stdlib/builtin/string.rbs +9 -2
  140. data/vendor/ruby-signature/stdlib/builtin/string_io.rbs +282 -11
  141. data/vendor/ruby-signature/stdlib/builtin/symbol.rbs +11 -13
  142. data/vendor/ruby-signature/stdlib/builtin/thread.rbs +25 -29
  143. data/vendor/ruby-signature/stdlib/builtin/thread_group.rbs +1 -1
  144. data/vendor/ruby-signature/stdlib/builtin/time.rbs +875 -567
  145. data/vendor/ruby-signature/stdlib/builtin/trace_point.rbs +243 -44
  146. data/vendor/ruby-signature/stdlib/builtin/unbound_method.rbs +103 -109
  147. data/vendor/ruby-signature/stdlib/coverage/coverage.rbs +62 -0
  148. data/vendor/ruby-signature/stdlib/csv/csv.rbs +773 -0
  149. data/vendor/ruby-signature/stdlib/erb/erb.rbs +375 -1
  150. data/vendor/ruby-signature/stdlib/find/find.rbs +0 -4
  151. data/vendor/ruby-signature/stdlib/ipaddr/ipaddr.rbs +247 -0
  152. data/vendor/ruby-signature/stdlib/pathname/pathname.rbs +1088 -16
  153. data/vendor/ruby-signature/stdlib/set/set.rbs +251 -27
  154. metadata +49 -44
  155. data/exe/ruby-signature +0 -3
  156. data/vendor/ruby-signature/exe/ruby-signature +0 -7
  157. data/vendor/ruby-signature/lib/ruby/signature/ast/annotation.rb +0 -29
  158. data/vendor/ruby-signature/lib/ruby/signature/ast/comment.rb +0 -29
  159. data/vendor/ruby-signature/lib/ruby/signature/ast/declarations.rb +0 -391
  160. data/vendor/ruby-signature/lib/ruby/signature/ast/members.rb +0 -364
  161. data/vendor/ruby-signature/lib/ruby/signature/buffer.rb +0 -52
  162. data/vendor/ruby-signature/lib/ruby/signature/builtin_names.rb +0 -54
  163. data/vendor/ruby-signature/lib/ruby/signature/cli.rb +0 -555
  164. data/vendor/ruby-signature/lib/ruby/signature/constant.rb +0 -28
  165. data/vendor/ruby-signature/lib/ruby/signature/constant_table.rb +0 -152
  166. data/vendor/ruby-signature/lib/ruby/signature/definition.rb +0 -172
  167. data/vendor/ruby-signature/lib/ruby/signature/definition_builder.rb +0 -921
  168. data/vendor/ruby-signature/lib/ruby/signature/environment.rb +0 -283
  169. data/vendor/ruby-signature/lib/ruby/signature/environment_loader.rb +0 -138
  170. data/vendor/ruby-signature/lib/ruby/signature/environment_walker.rb +0 -126
  171. data/vendor/ruby-signature/lib/ruby/signature/errors.rb +0 -189
  172. data/vendor/ruby-signature/lib/ruby/signature/location.rb +0 -104
  173. data/vendor/ruby-signature/lib/ruby/signature/method_type.rb +0 -125
  174. data/vendor/ruby-signature/lib/ruby/signature/namespace.rb +0 -93
  175. data/vendor/ruby-signature/lib/ruby/signature/prototype/rb.rb +0 -444
  176. data/vendor/ruby-signature/lib/ruby/signature/prototype/rbi.rb +0 -579
  177. data/vendor/ruby-signature/lib/ruby/signature/prototype/runtime.rb +0 -383
  178. data/vendor/ruby-signature/lib/ruby/signature/substitution.rb +0 -48
  179. data/vendor/ruby-signature/lib/ruby/signature/test/errors.rb +0 -63
  180. data/vendor/ruby-signature/lib/ruby/signature/test/hook.rb +0 -290
  181. data/vendor/ruby-signature/lib/ruby/signature/test/spy.rb +0 -327
  182. data/vendor/ruby-signature/lib/ruby/signature/test/test_helper.rb +0 -185
  183. data/vendor/ruby-signature/lib/ruby/signature/test/type_check.rb +0 -256
  184. data/vendor/ruby-signature/lib/ruby/signature/test.rb +0 -28
  185. data/vendor/ruby-signature/lib/ruby/signature/type_name.rb +0 -72
  186. data/vendor/ruby-signature/lib/ruby/signature/types.rb +0 -932
  187. data/vendor/ruby-signature/lib/ruby/signature/variance_calculator.rb +0 -140
  188. data/vendor/ruby-signature/lib/ruby/signature/vendorer.rb +0 -49
  189. data/vendor/ruby-signature/lib/ruby/signature/version.rb +0 -5
  190. data/vendor/ruby-signature/lib/ruby/signature/writer.rb +0 -271
@@ -1,74 +1,187 @@
1
- # [Random](Random) provides an interface to Ruby's
2
- # pseudo-random number generator, or PRNG. The PRNG produces a
3
- # deterministic sequence of bits which approximate true randomness. The
4
- # sequence may be represented by integers, floats, or binary strings.
5
- #
1
+ # Random provides an interface to Ruby's pseudo-random number generator, or
2
+ # PRNG. The PRNG produces a deterministic sequence of bits which approximate
3
+ # true randomness. The sequence may be represented by integers, floats, or
4
+ # binary strings.
5
+ #
6
6
  # The generator may be initialized with either a system-generated or
7
- # user-supplied seed value by using
8
- # [::srand](Random#method-c-srand).
9
- #
10
- # The class method [\#rand](Random#method-i-rand)
11
- # provides the base functionality of
12
- # [Kernel\#rand](https://ruby-doc.org/core-2.6.3/Kernel.html#method-i-rand)
13
- # along with better handling of floating point values. These are both
14
- # interfaces to Random::DEFAULT, the Ruby system PRNG.
15
- #
16
- # [::new](Random#method-c-new) will create a new PRNG
17
- # with a state independent of Random::DEFAULT, allowing multiple
18
- # generators with different seed values or sequence positions to exist
19
- # simultaneously. [Random](Random) objects can be
20
- # marshaled, allowing sequences to be saved and resumed.
21
- #
22
- # PRNGs are currently implemented as a modified Mersenne Twister with a
23
- # period of 2\*\*19937-1.
7
+ # user-supplied seed value by using Random.srand.
8
+ #
9
+ # The class method Random.rand provides the base functionality of Kernel.rand
10
+ # along with better handling of floating point values. These are both interfaces
11
+ # to Random::DEFAULT, the Ruby system PRNG.
12
+ #
13
+ # Random.new will create a new PRNG with a state independent of Random::DEFAULT,
14
+ # allowing multiple generators with different seed values or sequence positions
15
+ # to exist simultaneously. Random objects can be marshaled, allowing sequences
16
+ # to be saved and resumed.
17
+ #
18
+ # PRNGs are currently implemented as a modified Mersenne Twister with a period
19
+ # of 2**19937-1.
20
+ #
24
21
  class Random < Object
25
22
  include Random::Formatter
26
23
 
24
+ # Returns true if the two generators have the same internal state, otherwise
25
+ # false. Equivalent generators will return the same sequence of pseudo-random
26
+ # numbers. Two generators will generally have the same state only if they were
27
+ # initialized with the same seed
28
+ #
29
+ # Random.new == Random.new # => false
30
+ # Random.new(1234) == Random.new(1234) # => true
31
+ #
32
+ # and have the same invocation history.
33
+ #
34
+ # prng1 = Random.new(1234)
35
+ # prng2 = Random.new(1234)
36
+ # prng1 == prng2 # => true
37
+ #
38
+ # prng1.rand # => 0.1915194503788923
39
+ # prng1 == prng2 # => false
40
+ #
41
+ # prng2.rand # => 0.1915194503788923
42
+ # prng1 == prng2 # => true
43
+ #
27
44
  def ==: (untyped arg0) -> bool
28
45
 
46
+ # Returns a random binary string containing `size` bytes.
47
+ #
48
+ # random_string = Random.new.bytes(10) # => "\xD7:R\xAB?\x83\xCE\xFAkO"
49
+ # random_string.size # => 10
50
+ #
29
51
  def bytes: (Integer size) -> String
30
52
 
53
+ # Creates a new PRNG using `seed` to set the initial state. If `seed` is
54
+ # omitted, the generator is initialized with Random.new_seed.
55
+ #
56
+ # See Random.srand for more information on the use of seed values.
57
+ #
31
58
  def initialize: (?Integer seed) -> void
32
59
 
60
+ # When `max` is an Integer, `rand` returns a random integer greater than or
61
+ # equal to zero and less than `max`. Unlike Kernel.rand, when `max` is a
62
+ # negative integer or zero, `rand` raises an ArgumentError.
63
+ #
64
+ # prng = Random.new
65
+ # prng.rand(100) # => 42
66
+ #
67
+ # When `max` is a Float, `rand` returns a random floating point number between
68
+ # 0.0 and `max`, including 0.0 and excluding `max`.
69
+ #
70
+ # prng.rand(1.5) # => 1.4600282860034115
71
+ #
72
+ # When `max` is a Range, `rand` returns a random number where
73
+ # range.member?(number) == true.
74
+ #
75
+ # prng.rand(5..9) # => one of [5, 6, 7, 8, 9]
76
+ # prng.rand(5...9) # => one of [5, 6, 7, 8]
77
+ # prng.rand(5.0..9.0) # => between 5.0 and 9.0, including 9.0
78
+ # prng.rand(5.0...9.0) # => between 5.0 and 9.0, excluding 9.0
79
+ #
80
+ # Both the beginning and ending values of the range must respond to subtract
81
+ # (`-`) and add (`+`)methods, or rand will raise an ArgumentError.
82
+ #
33
83
  def rand: () -> Float
34
84
  | (Integer | ::Range[Integer] max) -> Integer
35
85
  | (Float | ::Range[Float] max) -> Float
36
86
 
37
- # Returns the seed value used to initialize the generator. This may be
38
- # used to initialize another generator with the same state at a later
39
- # time, causing it to produce the same sequence of numbers.
40
- #
41
- # ```ruby
42
- # prng1 = Random.new(1234)
43
- # prng1.seed #=> 1234
44
- # prng1.rand(100) #=> 47
45
- #
46
- # prng2 = Random.new(prng1.seed)
47
- # prng2.rand(100) #=> 47
48
- # ```
87
+ # Returns the seed value used to initialize the generator. This may be used to
88
+ # initialize another generator with the same state at a later time, causing it
89
+ # to produce the same sequence of numbers.
90
+ #
91
+ # prng1 = Random.new(1234)
92
+ # prng1.seed #=> 1234
93
+ # prng1.rand(100) #=> 47
94
+ #
95
+ # prng2 = Random.new(prng1.seed)
96
+ # prng2.rand(100) #=> 47
97
+ #
49
98
  def seed: () -> Integer
50
99
 
51
- # Returns an arbitrary seed value. This is used by
52
- # [::new](Random.downloaded.ruby_doc#method-c-new) when no seed value is
53
- # specified as an argument.
54
- #
55
- # ```ruby
56
- # Random.new_seed #=> 115032730400174366788466674494640623225
57
- # ```
100
+ # Returns an arbitrary seed value. This is used by Random.new when no seed value
101
+ # is specified as an argument.
102
+ #
103
+ # Random.new_seed #=> 115032730400174366788466674494640623225
104
+ #
58
105
  def self.new_seed: () -> Integer
59
106
 
107
+ # Alias of Random::DEFAULT.rand.
108
+ #
60
109
  def self.rand: (?Integer max) -> Numeric
61
110
 
111
+ # Seeds the system pseudo-random number generator, Random::DEFAULT, with
112
+ # `number`. The previous seed value is returned.
113
+ #
114
+ # If `number` is omitted, seeds the generator using a source of entropy provided
115
+ # by the operating system, if available (/dev/urandom on Unix systems or the RSA
116
+ # cryptographic provider on Windows), which is then combined with the time, the
117
+ # process id, and a sequence number.
118
+ #
119
+ # srand may be used to ensure repeatable sequences of pseudo-random numbers
120
+ # between different runs of the program. By setting the seed to a known value,
121
+ # programs can be made deterministic during testing.
122
+ #
123
+ # srand 1234 # => 268519324636777531569100071560086917274
124
+ # [ rand, rand ] # => [0.1915194503788923, 0.6221087710398319]
125
+ # [ rand(10), rand(1000) ] # => [4, 664]
126
+ # srand 1234 # => 1234
127
+ # [ rand, rand ] # => [0.1915194503788923, 0.6221087710398319]
128
+ #
62
129
  def self.srand: (?Integer number) -> Numeric
63
130
  end
64
131
 
132
+ # The default Pseudorandom number generator. Used by class methods of Random.
133
+ #
134
+ #
65
135
  Random::DEFAULT: Random
66
136
 
137
+ # Format raw random number as Random does
138
+ #
139
+ #
67
140
  module Random::Formatter
141
+ # SecureRandom.base64 generates a random base64 string.
142
+ #
143
+ # The argument *n* specifies the length, in bytes, of the random number to be
144
+ # generated. The length of the result string is about 4/3 of *n*.
145
+ #
146
+ # If *n* is not specified or is nil, 16 is assumed. It may be larger in the
147
+ # future.
148
+ #
149
+ # The result may contain A-Z, a-z, 0-9, "+", "/" and "=".
150
+ #
151
+ # require 'securerandom'
152
+ #
153
+ # SecureRandom.base64 #=> "/2BuBuLf3+WfSKyQbRcc/A=="
154
+ # SecureRandom.base64 #=> "6BbW0pxO0YENxn38HMUbcQ=="
155
+ #
156
+ # If a secure random number generator is not available, `NotImplementedError` is
157
+ # raised.
158
+ #
159
+ # See RFC 3548 for the definition of base64.
160
+ #
68
161
  def base64: (?Integer? n) -> String
69
162
 
163
+ # SecureRandom.hex generates a random hexadecimal string.
164
+ #
165
+ # The argument *n* specifies the length, in bytes, of the random number to be
166
+ # generated. The length of the resulting hexadecimal string is twice of *n*.
167
+ #
168
+ # If *n* is not specified or is nil, 16 is assumed. It may be larger in the
169
+ # future.
170
+ #
171
+ # The result may contain 0-9 and a-f.
172
+ #
173
+ # require 'securerandom'
174
+ #
175
+ # SecureRandom.hex #=> "eb693ec8252cd630102fd0d0fb7c3485"
176
+ # SecureRandom.hex #=> "91dc3bfb4de5b11d029d376634589b61"
177
+ #
178
+ # If a secure random number generator is not available, `NotImplementedError` is
179
+ # raised.
180
+ #
70
181
  def hex: (?Integer? n) -> String
71
182
 
183
+ # Generates formatted random number from raw random bytes. See Random#rand.
184
+ #
72
185
  def rand: () -> Float
73
186
  | (?Float? n) -> Float
74
187
  | (?Integer? n) -> Integer
@@ -77,8 +190,26 @@ module Random::Formatter
77
190
  | (?::Range[Integer]? n) -> Integer
78
191
  | (?::Range[Numeric]? n) -> Numeric
79
192
 
193
+ # SecureRandom.random_bytes generates a random binary string.
194
+ #
195
+ # The argument *n* specifies the length of the result string.
196
+ #
197
+ # If *n* is not specified or is nil, 16 is assumed. It may be larger in future.
198
+ #
199
+ # The result may contain any byte: "x00" - "xff".
200
+ #
201
+ # require 'securerandom'
202
+ #
203
+ # SecureRandom.random_bytes #=> "\xD8\\\xE0\xF4\r\xB2\xFC*WM\xFF\x83\x18\xF45\xB6"
204
+ # SecureRandom.random_bytes #=> "m\xDC\xFC/\a\x00Uf\xB2\xB2P\xBD\xFF6S\x97"
205
+ #
206
+ # If a secure random number generator is not available, `NotImplementedError` is
207
+ # raised.
208
+ #
80
209
  def random_bytes: (?Integer? n) -> String
81
210
 
211
+ # Generates formatted random number from raw random bytes. See Random#rand.
212
+ #
82
213
  def random_number: () -> Float
83
214
  | (?Float? n) -> Float
84
215
  | (?Integer? n) -> Integer
@@ -87,7 +218,50 @@ module Random::Formatter
87
218
  | (?::Range[Integer]? n) -> Integer
88
219
  | (?::Range[Numeric]? n) -> Numeric
89
220
 
221
+ # SecureRandom.urlsafe_base64 generates a random URL-safe base64 string.
222
+ #
223
+ # The argument *n* specifies the length, in bytes, of the random number to be
224
+ # generated. The length of the result string is about 4/3 of *n*.
225
+ #
226
+ # If *n* is not specified or is nil, 16 is assumed. It may be larger in the
227
+ # future.
228
+ #
229
+ # The boolean argument *padding* specifies the padding. If it is false or nil,
230
+ # padding is not generated. Otherwise padding is generated. By default, padding
231
+ # is not generated because "=" may be used as a URL delimiter.
232
+ #
233
+ # The result may contain A-Z, a-z, 0-9, "-" and "_". "=" is also used if
234
+ # *padding* is true.
235
+ #
236
+ # require 'securerandom'
237
+ #
238
+ # SecureRandom.urlsafe_base64 #=> "b4GOKm4pOYU_-BOXcrUGDg"
239
+ # SecureRandom.urlsafe_base64 #=> "UZLdOkzop70Ddx-IJR0ABg"
240
+ #
241
+ # SecureRandom.urlsafe_base64(nil, true) #=> "i0XQ-7gglIsHGV2_BNPrdQ=="
242
+ # SecureRandom.urlsafe_base64(nil, true) #=> "-M8rLhr7JEpJlqFGUMmOxg=="
243
+ #
244
+ # If a secure random number generator is not available, `NotImplementedError` is
245
+ # raised.
246
+ #
247
+ # See RFC 3548 for the definition of URL-safe base64.
248
+ #
90
249
  def urlsafe_base64: (?Integer? n, ?bool padding) -> String
91
250
 
251
+ # SecureRandom.uuid generates a random v4 UUID (Universally Unique IDentifier).
252
+ #
253
+ # require 'securerandom'
254
+ #
255
+ # SecureRandom.uuid #=> "2d931510-d99f-494a-8c67-87feb05e1594"
256
+ # SecureRandom.uuid #=> "bad85eb9-0713-4da7-8d36-07a8e4b00eab"
257
+ # SecureRandom.uuid #=> "62936e70-1815-439b-bf89-8492855a7e6b"
258
+ #
259
+ # The version 4 UUID is purely random (except the version). It doesn't contain
260
+ # meaningful information such as MAC addresses, timestamps, etc.
261
+ #
262
+ # The result contains 122 random bits (15.25 random bytes).
263
+ #
264
+ # See RFC 4122 for details of UUID.
265
+ #
92
266
  def uuid: () -> String
93
267
  end
@@ -1,10 +1,57 @@
1
+ # The module storing Ruby interpreter configurations on building.
2
+ #
3
+ # This file was created by mkconfig.rb when ruby was built. It contains build
4
+ # information for ruby which is used e.g. by mkmf to build compatible native
5
+ # extensions. Any changes made to this file will be lost the next time ruby is
6
+ # built.
7
+ #
1
8
  module RbConfig
9
+ # expands variable with given `val` value.
10
+ #
11
+ # RbConfig.expand("$(bindir)") # => /home/foobar/all-ruby/ruby19x/bin
12
+ #
13
+ def self.expand: (String val, ?Hash[String, String] config) -> String
14
+
15
+ def self.fire_update!: (String key, String val, ?Hash[String, String] mkconf, ?Hash[String, String] conf) -> Array[String]?
16
+
17
+ def self.ruby: () -> String
2
18
  end
3
19
 
20
+ # The hash configurations stored.
21
+ #
4
22
  RbConfig::CONFIG: Hash[String, String]
5
23
 
24
+ # DESTDIR on make install.
25
+ #
6
26
  RbConfig::DESTDIR: String
7
27
 
28
+ # Almost same with CONFIG. MAKEFILE_CONFIG has other variable reference like
29
+ # below.
30
+ #
31
+ # MAKEFILE_CONFIG["bindir"] = "$(exec_prefix)/bin"
32
+ #
33
+ # The values of this constant is used for creating Makefile.
34
+ #
35
+ # require 'rbconfig'
36
+ #
37
+ # print <<-END_OF_MAKEFILE
38
+ # prefix = #{Config::MAKEFILE_CONFIG['prefix']}
39
+ # exec_prefix = #{Config::MAKEFILE_CONFIG['exec_prefix']}
40
+ # bindir = #{Config::MAKEFILE_CONFIG['bindir']}
41
+ # END_OF_MAKEFILE
42
+ #
43
+ # => prefix = /usr/local
44
+ # exec_prefix = $(prefix)
45
+ # bindir = $(exec_prefix)/bin MAKEFILE_CONFIG = {}
46
+ #
47
+ # RbConfig.expand is used for resolving references like above in rbconfig.
48
+ #
49
+ # require 'rbconfig'
50
+ # p Config.expand(Config::MAKEFILE_CONFIG["bindir"])
51
+ # # => "/usr/local/bin"
52
+ #
8
53
  RbConfig::MAKEFILE_CONFIG: Hash[String, String]
9
54
 
55
+ # Ruby installed directory.
56
+ #
10
57
  RbConfig::TOPDIR: String
@@ -754,14 +754,14 @@ class String
754
754
  # : Replaces CRLF ("r\n") and CR ("r") with LF ("n") if value is true.
755
755
  #
756
756
  #
757
- def encode: (?Encoding | string encoding, ?Encoding | string from_encoding, ?invalid: :replace ?, ?undef: :replace ?, ?replace: String, ?fallback: Hash[String, String] | Proc | Method, ?xml: :text | :attr, ?universal_newline: true, ?cr_newline: true, ?crlf_newline: true) -> String
757
+ def encode: (?Encoding | string encoding, ?Encoding | string from_encoding, ?invalid: :replace ?, ?undef: :replace ?, ?replace: String, ?fallback: String::encode_fallback, ?xml: :text | :attr, ?universal_newline: true, ?cr_newline: true, ?crlf_newline: true) -> String
758
758
 
759
759
  # The first form transcodes the contents of *str* from str.encoding to
760
760
  # `encoding`. The second form transcodes the contents of *str* from src_encoding
761
761
  # to dst_encoding. The options Hash gives details for conversion. See
762
762
  # String#encode for details. Returns the string even if no changes were made.
763
763
  #
764
- def encode!: (?Encoding | string encoding, ?Encoding | string from_encoding, ?invalid: :replace ?, ?undef: :replace ?, ?replace: String, ?fallback: Hash[String, String] | Proc | Method, ?xml: :text | :attr, ?universal_newline: true, ?cr_newline: true, ?crlf_newline: true) -> self
764
+ def encode!: (?Encoding | string encoding, ?Encoding | string from_encoding, ?invalid: :replace ?, ?undef: :replace ?, ?replace: String, ?fallback: String::encode_fallback, ?xml: :text | :attr, ?universal_newline: true, ?cr_newline: true, ?crlf_newline: true) -> self
765
765
 
766
766
  # Returns the Encoding object that represents the encoding of obj.
767
767
  #
@@ -1005,6 +1005,7 @@ class String
1005
1005
  # The return value in this case is the value from block execution.
1006
1006
  #
1007
1007
  def match: (Regexp | string pattern, ?int pos) -> MatchData?
1008
+ | [A] (Regexp | string pattern, ?int pos) { (MatchData) -> A } -> A
1008
1009
 
1009
1010
  # Converts *pattern* to a `Regexp` (if it isn't already one), then returns a
1010
1011
  # `true` or `false` indicates whether the regexp is matched *str* or not without
@@ -1892,3 +1893,9 @@ class String
1892
1893
  #
1893
1894
  alias initialize_copy replace
1894
1895
  end
1896
+
1897
+ interface _ArefFromStringToString
1898
+ def []: (String) -> String
1899
+ end
1900
+
1901
+ type String::encode_fallback = Hash[String, String] | Proc | Method | _ArefFromStringToString
@@ -1,13 +1,284 @@
1
+ # Pseudo I/O on String object, with interface corresponding to IO.
2
+ #
3
+ # Commonly used to simulate `$stdio` or `$stderr`
4
+ #
5
+ # ### Examples
6
+ #
7
+ # require 'stringio'
8
+ #
9
+ # # Writing stream emulation
10
+ # io = StringIO.new
11
+ # io.puts "Hello World"
12
+ # io.string #=> "Hello World\n"
13
+ #
14
+ # # Reading stream emulation
15
+ # io = StringIO.new "first\nsecond\nlast\n"
16
+ # io.getc #=> "f"
17
+ # io.gets #=> "irst\n"
18
+ # io.read #=> "second\nlast\n"
19
+ #
1
20
  class StringIO
2
- def initialize: (?String, ?String) -> untyped
3
- def puts: (*untyped) -> void
4
- def readline: () -> String
5
- | (String) -> String
6
- def write: (String) -> void
7
- def flush: () -> void
8
- def string: -> String
9
- def close_read: -> nil
10
- def closed_read?: -> bool
11
- def close_write: -> nil
12
- def closed_write?: -> bool
21
+ # Creates new StringIO instance from with *string* and *mode*.
22
+ #
23
+ def initialize: (?String string, ?String? mode) -> void
24
+
25
+ # Equivalent to StringIO.new except that when it is called with a block, it
26
+ # yields with the new instance and closes it, and returns the result which
27
+ # returned from the block.
28
+ #
29
+ def self.open: [U] (?String string, ?String? mode) { (StringIO arg) -> U } -> U
30
+
31
+ def <<: (untyped arg0) -> self
32
+
33
+ # Puts stream into binary mode. See IO#binmode.
34
+ #
35
+ def binmode: () -> self
36
+
37
+ # Closes a StringIO. The stream is unavailable for any further data operations;
38
+ # an `IOError` is raised if such an attempt is made.
39
+ #
40
+ def close: () -> nil
41
+
42
+ # Closes the read end of a StringIO. Will raise an `IOError` if the receiver is
43
+ # not readable.
44
+ #
45
+ def close_read: () -> nil
46
+
47
+ # Closes the write end of a StringIO. Will raise an `IOError` if the receiver
48
+ # is not writeable.
49
+ #
50
+ def close_write: () -> nil
51
+
52
+ # Returns `true` if the stream is completely closed, `false` otherwise.
53
+ #
54
+ def closed?: () -> bool
55
+
56
+ # Returns `true` if the stream is not readable, `false` otherwise.
57
+ #
58
+ def closed_read?: () -> bool
59
+
60
+ # Returns `true` if the stream is not writable, `false` otherwise.
61
+ #
62
+ def closed_write?: () -> bool
63
+
64
+ # See IO#each.
65
+ #
66
+ def each: (?String sep, ?Integer limit, ?chomp: bool) { (String arg0) -> untyped } -> self
67
+ | (?String sep, ?Integer limit, ?chomp: bool) -> ::Enumerator[String, self]
68
+
69
+ # See IO#each_byte.
70
+ #
71
+ def each_byte: () { (Integer arg0) -> untyped } -> self
72
+ | () -> ::Enumerator[Integer, self]
73
+
74
+ # See IO#each_char.
75
+ #
76
+ def each_char: () { (String arg0) -> untyped } -> self
77
+ | () -> ::Enumerator[String, self]
78
+
79
+ # See IO#each_codepoint.
80
+ #
81
+ def each_codepoint: () { (Integer arg0) -> untyped } -> self
82
+ | () -> ::Enumerator[Integer, self]
83
+
84
+ # Returns true if the stream is at the end of the data (underlying string). The
85
+ # stream must be opened for reading or an `IOError` will be raised.
86
+ #
87
+ def eof: () -> bool
88
+
89
+ # Raises NotImplementedError.
90
+ #
91
+ def fcntl: (Integer integer_cmd, String | Integer arg) -> Integer
92
+
93
+ # Returns `nil`. Just for compatibility to IO.
94
+ #
95
+ def fileno: () -> nil
96
+
97
+ # Returns an object itself. Just for compatibility to IO.
98
+ #
99
+ def flush: () -> self
100
+
101
+ # Returns 0. Just for compatibility to IO.
102
+ #
103
+ def fsync: () -> Integer?
104
+
105
+ # See IO#getbyte.
106
+ #
107
+ def getbyte: () -> Integer?
108
+
109
+ # See IO#getc.
110
+ #
111
+ def getc: () -> String?
112
+
113
+ # See IO#gets.
114
+ #
115
+ def gets: (?String sep, ?Integer limit, ?chomp: bool) -> String?
116
+
117
+ # Returns the Encoding of the internal string if conversion is specified.
118
+ # Otherwise returns `nil`.
119
+ #
120
+ def internal_encoding: () -> Encoding
121
+
122
+ # Returns the Encoding object that represents the encoding of the file. If the
123
+ # stream is write mode and no encoding is specified, returns `nil`.
124
+ #
125
+ def external_encoding: () -> Encoding
126
+
127
+ # Returns `false`. Just for compatibility to IO.
128
+ #
129
+ def isatty: () -> bool
130
+
131
+ # Returns the current line number. The stream must be opened for reading.
132
+ # `lineno` counts the number of times `gets` is called, rather than the number
133
+ # of newlines encountered. The two values will differ if `gets` is called with
134
+ # a separator other than newline. See also the `$.` variable.
135
+ #
136
+ def lineno: () -> Integer
137
+
138
+ # Manually sets the current line number to the given value. `$.` is updated only
139
+ # on the next read.
140
+ #
141
+ def lineno=: (Integer arg0) -> Integer
142
+
143
+ # Returns `nil`. Just for compatibility to IO.
144
+ #
145
+ def pid: () -> nil
146
+
147
+ # Returns the current offset (in bytes).
148
+ #
149
+ def pos: () -> Integer
150
+
151
+ # Seeks to the given position (in bytes).
152
+ #
153
+ def pos=: (Integer arg0) -> Integer
154
+
155
+ def print: (*untyped arg0) -> nil
156
+
157
+ def printf: (String format_string, *untyped arg0) -> nil
158
+
159
+ # See IO#putc.
160
+ #
161
+ def putc: (Numeric | String arg0) -> untyped
162
+
163
+ def puts: (*untyped arg0) -> nil
164
+
165
+ # See IO#read.
166
+ #
167
+ def read: (?Integer length, ?String outbuf) -> String?
168
+
169
+ def read_nonblock: (Integer len) -> String
170
+ | (Integer len, ?String buf) -> String
171
+
172
+ def readbyte: () -> Integer
173
+
174
+ def readchar: () -> String
175
+
176
+ def readline: (?String sep, ?Integer limit) -> String
177
+
178
+ # See IO#readlines.
179
+ #
180
+ def readlines: (?String sep, ?Integer limit, ?chomp: bool) -> ::Array[String]
181
+
182
+ def readpartial: (Integer maxlen) -> String
183
+ | (Integer maxlen, ?String outbuf) -> String
184
+
185
+ # Reinitializes the stream with the given *other_StrIO* or *string* and *mode*
186
+ # (see StringIO#new).
187
+ #
188
+ def reopen: (StringIO other) -> self
189
+ | (String other, ?String mode_str) -> self
190
+
191
+ # Positions the stream to the beginning of input, resetting `lineno` to zero.
192
+ #
193
+ def rewind: () -> Integer
194
+
195
+ # Seeks to a given offset *amount* in the stream according to the value of
196
+ # *whence* (see IO#seek).
197
+ #
198
+ def seek: (Integer amount, ?Integer whence) -> Integer
199
+
200
+ # Specify the encoding of the StringIO as *ext_enc*. Use the default external
201
+ # encoding if *ext_enc* is nil. 2nd argument *int_enc* and optional hash *opt*
202
+ # argument are ignored; they are for API compatibility to IO.
203
+ #
204
+ def set_encoding: (?String | Encoding ext_or_ext_int_enc) -> self
205
+ | (?String | Encoding ext_or_ext_int_enc, ?String | Encoding int_enc) -> self
206
+
207
+ # Returns underlying String object, the subject of IO.
208
+ #
209
+ def string: () -> String
210
+
211
+ # Changes underlying String object, the subject of IO.
212
+ #
213
+ def string=: (String str) -> String
214
+
215
+ # Returns the size of the buffer string.
216
+ #
217
+ def size: () -> Integer
218
+
219
+ # Returns `true` always.
220
+ #
221
+ def sync: () -> bool
222
+
223
+ # Returns the argument unchanged. Just for compatibility to IO.
224
+ #
225
+ def sync=: (bool arg0) -> bool
226
+
227
+ def sysread: (Integer maxlen, String outbuf) -> String
228
+
229
+ def syswrite: (String arg0) -> Integer
230
+
231
+ # Returns the current offset (in bytes).
232
+ #
233
+ def tell: () -> Integer
234
+
235
+ # Returns `false`. Just for compatibility to IO.
236
+ #
237
+ def tty?: () -> bool
238
+
239
+ # See IO#ungetbyte
240
+ #
241
+ def ungetbyte: (String | Integer arg0) -> nil
242
+
243
+ # Pushes back one character (passed as a parameter) such that a subsequent
244
+ # buffered read will return it. There is no limitation for multiple pushbacks
245
+ # including pushing back behind the beginning of the buffer string.
246
+ #
247
+ def ungetc: (String arg0) -> nil
248
+
249
+ # Appends the given string to the underlying buffer string. The stream must be
250
+ # opened for writing. If the argument is not a string, it will be converted to
251
+ # a string using `to_s`. Returns the number of bytes written. See IO#write.
252
+ #
253
+ def write: (String arg0) -> Integer
254
+
255
+ # This is a deprecated alias for #each_byte.
256
+ #
257
+ def bytes: () { (Integer arg0) -> untyped } -> self
258
+ | () -> ::Enumerator[Integer, self]
259
+
260
+ # This is a deprecated alias for #each_char.
261
+ #
262
+ def chars: () { (String arg0) -> untyped } -> self
263
+ | () -> ::Enumerator[String, self]
264
+
265
+ # This is a deprecated alias for #each_codepoint.
266
+ #
267
+ def codepoints: () { (Integer arg0) -> untyped } -> self
268
+ | () -> ::Enumerator[Integer, self]
269
+
270
+ # See IO#each.
271
+ #
272
+ def each_line: (?String sep, ?Integer limit, ?chomp: bool) { (String arg0) -> untyped } -> self
273
+ | (?String sep, ?Integer limit, ?chomp: bool) -> ::Enumerator[String, self]
274
+
275
+ # Returns true if the stream is at the end of the data (underlying string). The
276
+ # stream must be opened for reading or an `IOError` will be raised.
277
+ #
278
+ def eof?: () -> bool
279
+
280
+ # This is a deprecated alias for #each_line.
281
+ #
282
+ def lines: (?String sep, ?Integer limit) { (String arg0) -> untyped } -> self
283
+ | (?String sep, ?Integer limit) -> ::Enumerator[String, self]
13
284
  end