rbs 0.13.1 → 0.18.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +9 -5
- data/.gitignore +0 -1
- data/CHANGELOG.md +38 -2
- data/Gemfile +4 -0
- data/README.md +9 -3
- data/Rakefile +19 -1
- data/Steepfile +1 -1
- data/bin/annotate-with-rdoc +1 -1
- data/bin/setup +0 -2
- data/bin/test_runner.rb +15 -1
- data/{stdlib/builtin → core}/array.rbs +124 -120
- data/{stdlib/builtin → core}/basic_object.rbs +54 -54
- data/{stdlib/builtin → core}/binding.rbs +42 -42
- data/core/builtin.rbs +70 -0
- data/{stdlib/builtin → core}/class.rbs +33 -33
- data/{stdlib/builtin → core}/comparable.rbs +0 -0
- data/{stdlib/builtin → core}/complex.rbs +90 -90
- data/{stdlib/builtin → core}/constants.rbs +0 -0
- data/{stdlib/builtin → core}/data.rbs +0 -0
- data/{stdlib/builtin → core}/deprecated.rbs +0 -0
- data/{stdlib/builtin → core}/dir.rbs +1 -1
- data/{stdlib/builtin → core}/encoding.rbs +33 -33
- data/{stdlib/builtin → core}/enumerable.rbs +99 -92
- data/{stdlib/builtin → core}/enumerator.rbs +40 -40
- data/{stdlib/builtin → core}/errno.rbs +0 -0
- data/{stdlib/builtin → core}/errors.rbs +2 -2
- data/{stdlib/builtin → core}/exception.rbs +50 -50
- data/{stdlib/builtin → core}/false_class.rbs +6 -6
- data/{stdlib/builtin → core}/fiber.rbs +14 -14
- data/{stdlib/builtin → core}/fiber_error.rbs +1 -1
- data/{stdlib/builtin → core}/file.rbs +0 -0
- data/{stdlib/builtin → core}/file_test.rbs +0 -0
- data/{stdlib/builtin → core}/float.rbs +161 -161
- data/{stdlib/builtin → core}/gc.rbs +3 -3
- data/{stdlib/builtin → core}/hash.rbs +15 -15
- data/{stdlib/builtin → core}/integer.rbs +0 -0
- data/{stdlib/builtin → core}/io.rbs +89 -89
- data/{stdlib/builtin → core}/kernel.rbs +70 -154
- data/{stdlib/builtin → core}/marshal.rbs +0 -0
- data/{stdlib/builtin → core}/match_data.rbs +1 -1
- data/{stdlib/builtin → core}/math.rbs +0 -0
- data/{stdlib/builtin → core}/method.rbs +19 -19
- data/{stdlib/builtin → core}/module.rbs +13 -13
- data/{stdlib/builtin → core}/nil_class.rbs +20 -20
- data/{stdlib/builtin → core}/numeric.rbs +101 -101
- data/{stdlib/builtin → core}/object.rbs +173 -173
- data/core/object_space.rbs +98 -0
- data/{stdlib/builtin → core}/proc.rbs +91 -91
- data/{stdlib/builtin → core}/process.rbs +0 -0
- data/{stdlib/builtin → core}/random.rbs +1 -1
- data/{stdlib/builtin → core}/range.rbs +4 -6
- data/{stdlib/builtin → core}/rational.rbs +83 -83
- data/{stdlib/builtin → core}/rb_config.rbs +0 -0
- data/{stdlib/builtin → core}/regexp.rbs +0 -0
- data/{stdlib/builtin → core}/ruby_vm.rbs +0 -0
- data/{stdlib/builtin → core}/signal.rbs +7 -7
- data/{stdlib/builtin → core}/string.rbs +10 -10
- data/{stdlib/builtin → core}/string_io.rbs +8 -8
- data/{stdlib/builtin → core}/struct.rbs +2 -2
- data/{stdlib/builtin → core}/symbol.rbs +1 -1
- data/{stdlib/builtin → core}/thread.rbs +189 -189
- data/{stdlib/builtin → core}/thread_group.rbs +2 -2
- data/{stdlib/builtin → core}/time.rbs +0 -0
- data/{stdlib/builtin → core}/trace_point.rbs +0 -0
- data/{stdlib/builtin → core}/true_class.rbs +10 -10
- data/{stdlib/builtin → core}/unbound_method.rbs +0 -0
- data/{stdlib/builtin → core}/warning.rbs +1 -1
- data/docs/CONTRIBUTING.md +1 -0
- data/docs/repo.md +125 -0
- data/docs/syntax.md +50 -6
- data/goodcheck.yml +22 -5
- data/lib/rbs.rb +1 -0
- data/lib/rbs/ast/comment.rb +1 -1
- data/lib/rbs/cli.rb +105 -103
- data/lib/rbs/definition.rb +9 -4
- data/lib/rbs/definition_builder.rb +54 -22
- data/lib/rbs/environment.rb +1 -1
- data/lib/rbs/environment_loader.rb +79 -105
- data/lib/rbs/environment_walker.rb +58 -29
- data/lib/rbs/namespace.rb +1 -1
- data/lib/rbs/parser.rb +3153 -0
- data/lib/rbs/parser.y +25 -11
- data/lib/rbs/prototype/rb.rb +186 -25
- data/lib/rbs/prototype/runtime.rb +18 -7
- data/lib/rbs/repository.rb +121 -0
- data/lib/rbs/test/hook.rb +27 -15
- data/lib/rbs/test/setup.rb +5 -3
- data/lib/rbs/test/setup_helper.rb +4 -4
- data/lib/rbs/test/tester.rb +4 -1
- data/lib/rbs/test/type_check.rb +18 -7
- data/lib/rbs/type_name.rb +3 -2
- data/lib/rbs/variance_calculator.rb +1 -1
- data/lib/rbs/vendorer.rb +38 -16
- data/lib/rbs/version.rb +1 -1
- data/lib/rbs/writer.rb +1 -1
- data/sig/cli.rbs +58 -0
- data/sig/constant.rbs +2 -2
- data/sig/constant_table.rbs +11 -11
- data/sig/declarations.rbs +2 -2
- data/sig/definition.rbs +10 -5
- data/sig/definition_builder.rbs +4 -1
- data/sig/environment_loader.rbs +92 -46
- data/sig/members.rbs +2 -2
- data/sig/method_types.rbs +1 -1
- data/sig/namespace.rbs +4 -4
- data/sig/parser.rbs +25 -0
- data/sig/polyfill.rbs +42 -0
- data/sig/rbs.rbs +8 -0
- data/sig/repository.rbs +79 -0
- data/sig/substitution.rbs +3 -3
- data/sig/typename.rbs +1 -1
- data/sig/types.rbs +1 -1
- data/sig/vendorer.rbs +44 -0
- data/sig/writer.rbs +15 -15
- data/stdlib/abbrev/{abbrev.rbs → 0/abbrev.rbs} +0 -0
- data/stdlib/base64/{base64.rbs → 0/base64.rbs} +1 -1
- data/stdlib/benchmark/{benchmark.rbs → 0/benchmark.rbs} +2 -2
- data/stdlib/{bigdecimal/math → bigdecimal-math/0}/big_math.rbs +0 -0
- data/stdlib/bigdecimal/{big_decimal.rbs → 0/big_decimal.rbs} +0 -0
- data/stdlib/coverage/{coverage.rbs → 0/coverage.rbs} +2 -2
- data/stdlib/csv/{csv.rbs → 0/csv.rbs} +4 -4
- data/stdlib/date/{date.rbs → 0/date.rbs} +4 -4
- data/stdlib/date/{date_time.rbs → 0/date_time.rbs} +1 -1
- data/stdlib/dbm/0/dbm.rbs +277 -0
- data/stdlib/erb/{erb.rbs → 0/erb.rbs} +0 -0
- data/stdlib/fiber/{fiber.rbs → 0/fiber.rbs} +0 -0
- data/stdlib/find/{find.rbs → 0/find.rbs} +12 -12
- data/stdlib/forwardable/{forwardable.rbs → 0/forwardable.rbs} +0 -0
- data/stdlib/ipaddr/{ipaddr.rbs → 0/ipaddr.rbs} +0 -0
- data/stdlib/json/{json.rbs → 0/json.rbs} +0 -0
- data/stdlib/logger/{formatter.rbs → 0/formatter.rbs} +0 -0
- data/stdlib/logger/{log_device.rbs → 0/log_device.rbs} +1 -1
- data/stdlib/logger/{logger.rbs → 0/logger.rbs} +1 -1
- data/stdlib/logger/{period.rbs → 0/period.rbs} +0 -0
- data/stdlib/logger/{severity.rbs → 0/severity.rbs} +0 -0
- data/stdlib/mutex_m/{mutex_m.rbs → 0/mutex_m.rbs} +0 -0
- data/stdlib/pathname/{pathname.rbs → 0/pathname.rbs} +40 -40
- data/stdlib/prime/{integer-extension.rbs → 0/integer-extension.rbs} +0 -0
- data/stdlib/prime/{prime.rbs → 0/prime.rbs} +1 -1
- data/stdlib/pstore/0/pstore.rbs +287 -0
- data/stdlib/pty/{pty.rbs → 0/pty.rbs} +1 -1
- data/stdlib/securerandom/{securerandom.rbs → 0/securerandom.rbs} +0 -0
- data/stdlib/set/{set.rbs → 0/set.rbs} +10 -10
- data/stdlib/singleton/0/singleton.rbs +111 -0
- data/stdlib/tmpdir/{tmpdir.rbs → 0/tmpdir.rbs} +12 -12
- data/stdlib/tsort/0/cyclic.rbs +4 -0
- data/stdlib/tsort/0/interfaces.rbs +19 -0
- data/stdlib/tsort/0/tsort.rbs +363 -0
- data/stdlib/uri/{file.rbs → 0/file.rbs} +0 -0
- data/stdlib/uri/{generic.rbs → 0/generic.rbs} +1 -1
- data/stdlib/uri/{http.rbs → 0/http.rbs} +0 -0
- data/stdlib/uri/{https.rbs → 0/https.rbs} +0 -0
- data/stdlib/uri/{ldap.rbs → 0/ldap.rbs} +0 -0
- data/stdlib/uri/{ldaps.rbs → 0/ldaps.rbs} +0 -0
- data/stdlib/yaml/0/dbm.rbs +221 -0
- data/stdlib/yaml/0/store.rbs +53 -0
- data/stdlib/zlib/{zlib.rbs → 0/zlib.rbs} +0 -0
- data/steep/Gemfile.lock +9 -9
- metadata +109 -94
- data/stdlib/builtin/builtin.rbs +0 -42
@@ -1,18 +1,18 @@
|
|
1
1
|
# The [Kernel](Kernel) module is included by class
|
2
2
|
# [Object](https://ruby-doc.org/core-2.6.3/Object.html), so its methods
|
3
3
|
# are available in every Ruby object.
|
4
|
-
#
|
4
|
+
#
|
5
5
|
# The [Kernel](Kernel) instance methods are documented
|
6
6
|
# in class [Object](https://ruby-doc.org/core-2.6.3/Object.html) while the
|
7
7
|
# module methods are documented here. These methods are called without a
|
8
8
|
# receiver and thus can be called in functional form:
|
9
|
-
#
|
9
|
+
#
|
10
10
|
# ```ruby
|
11
11
|
# sprintf "%.1f", 1.234 #=> "1.2"
|
12
12
|
# ```
|
13
13
|
module Kernel
|
14
14
|
private
|
15
|
-
|
15
|
+
|
16
16
|
def caller: (?Integer start_or_range, ?Integer length) -> ::Array[String]?
|
17
17
|
| (?::Range[Integer] start_or_range) -> ::Array[String]?
|
18
18
|
| () -> ::Array[String]
|
@@ -24,13 +24,13 @@ module Kernel
|
|
24
24
|
| () { (Object tag) -> untyped } -> untyped
|
25
25
|
|
26
26
|
# In a perfect world this should be:
|
27
|
-
#
|
27
|
+
#
|
28
28
|
# returns(T.class_of(T.self_type))
|
29
|
-
#
|
29
|
+
#
|
30
30
|
# but that doesn't work (yet). Even making it:
|
31
|
-
#
|
31
|
+
#
|
32
32
|
# returns(Class)
|
33
|
-
#
|
33
|
+
#
|
34
34
|
# is very surprising since users expect their methods to be present.
|
35
35
|
# So we settle for untyped.
|
36
36
|
def `class`: () -> untyped
|
@@ -42,7 +42,7 @@ module Kernel
|
|
42
42
|
|
43
43
|
# Returns `true` if `yield` would execute a block in the current context.
|
44
44
|
# The `iterator?` form is mildly deprecated.
|
45
|
-
#
|
45
|
+
#
|
46
46
|
# ```ruby
|
47
47
|
# def try
|
48
48
|
# if block_given?
|
@@ -59,7 +59,7 @@ module Kernel
|
|
59
59
|
alias block_given? iterator?
|
60
60
|
|
61
61
|
# Returns the names of the current local variables.
|
62
|
-
#
|
62
|
+
#
|
63
63
|
# ```ruby
|
64
64
|
# fred = 1
|
65
65
|
# for i in 1..10
|
@@ -71,28 +71,6 @@ module Kernel
|
|
71
71
|
|
72
72
|
def srand: (?Numeric number) -> Numeric
|
73
73
|
|
74
|
-
def !~: (untyped other) -> bool
|
75
|
-
|
76
|
-
def <=>: (untyped other) -> Integer?
|
77
|
-
|
78
|
-
def ===: (untyped other) -> bool
|
79
|
-
|
80
|
-
def =~: (untyped other) -> NilClass
|
81
|
-
|
82
|
-
def clone: (?freeze: (TrueClass | FalseClass)) -> self
|
83
|
-
|
84
|
-
def display: (?IO port) -> NilClass
|
85
|
-
|
86
|
-
def dup: () -> self
|
87
|
-
|
88
|
-
def enum_for: (Symbol method, *untyped args) -> ::Enumerator[untyped, untyped]
|
89
|
-
| (Symbol method, *untyped args) { (*untyped args) -> (Integer|Float|nil) } -> ::Enumerator[untyped, untyped]
|
90
|
-
alias to_enum enum_for
|
91
|
-
|
92
|
-
def eql?: (untyped other) -> bool
|
93
|
-
|
94
|
-
def `extend`: (*Module mod) -> self
|
95
|
-
|
96
74
|
# Creates a subprocess. If a block is specified, that block is run in the
|
97
75
|
# subprocess, and the subprocess terminates with a status of zero.
|
98
76
|
# Otherwise, the `fork` call returns twice, once in the parent, returning
|
@@ -102,93 +80,31 @@ module Kernel
|
|
102
80
|
# collect the termination statuses of its children or use `Process.detach`
|
103
81
|
# to register disinterest in their status; otherwise, the operating system
|
104
82
|
# may accumulate zombie processes.
|
105
|
-
#
|
83
|
+
#
|
106
84
|
# The thread calling fork is the only thread in the created child process.
|
107
85
|
# fork doesn’t copy other threads.
|
108
|
-
#
|
86
|
+
#
|
109
87
|
# If fork is not usable, Process.respond\_to?(:fork) returns false.
|
110
|
-
#
|
88
|
+
#
|
111
89
|
# Note that fork(2) is not available on some platforms like Windows and
|
112
90
|
# NetBSD 4. Therefore you should use spawn() instead of fork().
|
113
91
|
def fork: () -> Integer?
|
114
92
|
| () { () -> untyped } -> Integer?
|
115
93
|
|
116
|
-
def freeze: () -> self
|
117
|
-
|
118
|
-
def frozen?: () -> bool
|
119
|
-
|
120
|
-
def hash: () -> Integer
|
121
|
-
|
122
94
|
def initialize_copy: (self object) -> self
|
123
95
|
|
124
|
-
def inspect: () -> String
|
125
|
-
|
126
|
-
def instance_of?: (Class arg0) -> bool
|
127
|
-
|
128
|
-
def instance_variable_defined?: (Symbol | String arg0) -> bool
|
129
|
-
|
130
|
-
def instance_variable_get: (Symbol | String arg0) -> untyped
|
131
|
-
|
132
|
-
def instance_variable_set: [T] (Symbol | String arg0, T arg1) -> T
|
133
|
-
|
134
|
-
def instance_variables: () -> ::Array[Symbol]
|
135
|
-
|
136
|
-
def is_a?: (Class | Module arg0) -> bool
|
137
|
-
alias kind_of? is_a?
|
138
|
-
|
139
|
-
def method: (Symbol | String arg0) -> Method
|
140
|
-
|
141
|
-
def methods: (?bool regular) -> ::Array[Symbol]
|
142
|
-
|
143
|
-
def `nil?`: () -> FalseClass
|
144
|
-
|
145
|
-
def private_methods: (?bool all) -> ::Array[Symbol]
|
146
|
-
|
147
|
-
def protected_methods: (?bool all) -> ::Array[Symbol]
|
148
|
-
|
149
|
-
def public_method: (Symbol | String arg0) -> Method
|
150
|
-
|
151
|
-
def public_methods: (?bool all) -> ::Array[Symbol]
|
152
|
-
|
153
|
-
def `public_send`: (Symbol | String arg0, *untyped args) -> untyped
|
154
|
-
| (Symbol | String arg0, *untyped args) { (*untyped) -> untyped } -> untyped
|
155
|
-
|
156
|
-
def remove_instance_variable: (Symbol | String arg0) -> untyped
|
157
|
-
|
158
|
-
def `send`: (String | Symbol arg0, *untyped arg1) -> untyped
|
159
|
-
| (String | Symbol arg0, *untyped arg1) { (*untyped) -> untyped } -> untyped
|
160
|
-
|
161
|
-
def `singleton_class`: () -> Class
|
162
|
-
|
163
|
-
def singleton_method: (Symbol | String arg0) -> Method
|
164
|
-
|
165
|
-
def singleton_methods: (?bool all) -> ::Array[Symbol]
|
166
|
-
|
167
|
-
def taint: () -> self
|
168
|
-
alias untrust taint
|
169
|
-
|
170
|
-
def tainted?: () -> bool
|
171
|
-
alias untrusted? tainted?
|
172
|
-
|
173
|
-
def tap: () { (untyped x) -> void } -> self
|
174
|
-
|
175
|
-
def to_s: () -> String
|
176
|
-
|
177
|
-
def untaint: () -> self
|
178
|
-
alias trust untaint
|
179
|
-
|
180
96
|
# Returns `arg` as an [Array](https://ruby-doc.org/core-2.6.3/Array.html)
|
181
97
|
# .
|
182
|
-
#
|
98
|
+
#
|
183
99
|
# First tries to call `to_ary` on `arg`, then `to_a` . If `arg` does not
|
184
100
|
# respond to `to_ary` or `to_a`, returns an
|
185
101
|
# [Array](https://ruby-doc.org/core-2.6.3/Array.html) of length 1
|
186
102
|
# containing `arg` .
|
187
|
-
#
|
103
|
+
#
|
188
104
|
# If `to_ary` or `to_a` returns something other than an
|
189
105
|
# [Array](https://ruby-doc.org/core-2.6.3/Array.html), raises a
|
190
106
|
# `TypeError` .
|
191
|
-
#
|
107
|
+
#
|
192
108
|
# ```ruby
|
193
109
|
# Array(["a", "b"]) #=> ["a", "b"]
|
194
110
|
# Array(1..5) #=> [1, 2, 3, 4, 5]
|
@@ -245,7 +161,7 @@ module Kernel
|
|
245
161
|
# at the point of call. This object can be used when calling `eval` to
|
246
162
|
# execute the evaluated command in this environment. See also the
|
247
163
|
# description of class `Binding` .
|
248
|
-
#
|
164
|
+
#
|
249
165
|
# ```ruby
|
250
166
|
# def get_binding(param)
|
251
167
|
# binding
|
@@ -260,7 +176,7 @@ module Kernel
|
|
260
176
|
# to return a status code to the invoking environment. `true` and `FALSE`
|
261
177
|
# of *status* means success and failure respectively. The interpretation
|
262
178
|
# of other integer values are system dependent.
|
263
|
-
#
|
179
|
+
#
|
264
180
|
# ```ruby
|
265
181
|
# begin
|
266
182
|
# exit
|
@@ -270,25 +186,25 @@ module Kernel
|
|
270
186
|
# end
|
271
187
|
# puts "after begin block"
|
272
188
|
# ```
|
273
|
-
#
|
189
|
+
#
|
274
190
|
# *produces:*
|
275
|
-
#
|
191
|
+
#
|
276
192
|
# rescued a SystemExit exception
|
277
193
|
# after begin block
|
278
|
-
#
|
194
|
+
#
|
279
195
|
# Just prior to termination, Ruby executes any `at_exit` functions (see
|
280
196
|
# Kernel::at\_exit) and runs any object finalizers (see
|
281
197
|
# [ObjectSpace.define\_finalizer](https://ruby-doc.org/core-2.6.3/ObjectSpace.html#method-c-define_finalizer)
|
282
198
|
# ).
|
283
|
-
#
|
199
|
+
#
|
284
200
|
# ```ruby
|
285
201
|
# at_exit { puts "at_exit function" }
|
286
202
|
# ObjectSpace.define_finalizer("string", proc { puts "in finalizer" })
|
287
203
|
# exit
|
288
204
|
# ```
|
289
|
-
#
|
205
|
+
#
|
290
206
|
# *produces:*
|
291
|
-
#
|
207
|
+
#
|
292
208
|
# at_exit function
|
293
209
|
# in finalizer
|
294
210
|
def exit: () -> bot
|
@@ -325,18 +241,18 @@ module Kernel
|
|
325
241
|
def gets: (?String arg0, ?Integer arg1) -> String?
|
326
242
|
|
327
243
|
# Returns an array of the names of global variables.
|
328
|
-
#
|
244
|
+
#
|
329
245
|
# ```ruby
|
330
246
|
# global_variables.grep /std/ #=> [:$stdin, :$stdout, :$stderr]
|
331
247
|
# ```
|
332
248
|
def global_variables: () -> ::Array[Symbol]
|
333
249
|
|
334
|
-
def load: (String filename, ?
|
250
|
+
def load: (String filename, ?boolish) -> bool
|
335
251
|
|
336
252
|
# Repeatedly executes the block.
|
337
|
-
#
|
253
|
+
#
|
338
254
|
# If no block is given, an enumerator is returned instead.
|
339
|
-
#
|
255
|
+
#
|
340
256
|
# ```ruby
|
341
257
|
# loop do
|
342
258
|
# print "Input: "
|
@@ -345,18 +261,18 @@ module Kernel
|
|
345
261
|
# # ...
|
346
262
|
# end
|
347
263
|
# ```
|
348
|
-
#
|
264
|
+
#
|
349
265
|
# [StopIteration](https://ruby-doc.org/core-2.6.3/StopIteration.html)
|
350
266
|
# raised in the block breaks the loop. In this case, loop returns the
|
351
267
|
# "result" value stored in the exception.
|
352
|
-
#
|
268
|
+
#
|
353
269
|
# ```ruby
|
354
270
|
# enum = Enumerator.new { |y|
|
355
271
|
# y << "one"
|
356
272
|
# y << "two"
|
357
273
|
# :ok
|
358
274
|
# }
|
359
|
-
#
|
275
|
+
#
|
360
276
|
# result = loop {
|
361
277
|
# puts enum.next
|
362
278
|
# } #=> :ok
|
@@ -372,16 +288,16 @@ module Kernel
|
|
372
288
|
# the output record separator ( `$\` ) is not `nil`, it will be appended
|
373
289
|
# to the output. If no arguments are given, prints `$_` . Objects that
|
374
290
|
# aren’t strings will be converted by calling their `to_s` method.
|
375
|
-
#
|
291
|
+
#
|
376
292
|
# ```ruby
|
377
293
|
# print "cat", [1,2,3], 99, "\n"
|
378
294
|
# $, = ", "
|
379
295
|
# $\ = "\n"
|
380
296
|
# print "cat", [1,2,3], 99
|
381
297
|
# ```
|
382
|
-
#
|
298
|
+
#
|
383
299
|
# *produces:*
|
384
|
-
#
|
300
|
+
#
|
385
301
|
# cat12399
|
386
302
|
# cat, 1, 2, 3, 99
|
387
303
|
def print: (*Kernel args) -> nil
|
@@ -408,35 +324,35 @@ module Kernel
|
|
408
324
|
# If called without an argument, or if `max.to_i.abs == 0`, rand returns
|
409
325
|
# a pseudo-random floating point number between 0.0 and 1.0, including 0.0
|
410
326
|
# and excluding 1.0.
|
411
|
-
#
|
327
|
+
#
|
412
328
|
# ```ruby
|
413
329
|
# rand #=> 0.2725926052826416
|
414
330
|
# ```
|
415
|
-
#
|
331
|
+
#
|
416
332
|
# When `max.abs` is greater than or equal to 1, `rand` returns a
|
417
333
|
# pseudo-random integer greater than or equal to 0 and less than
|
418
334
|
# `max.to_i.abs` .
|
419
|
-
#
|
335
|
+
#
|
420
336
|
# ```ruby
|
421
337
|
# rand(100) #=> 12
|
422
338
|
# ```
|
423
|
-
#
|
339
|
+
#
|
424
340
|
# When `max` is a [Range](https://ruby-doc.org/core-2.6.3/Range.html),
|
425
341
|
# `rand` returns a random number where range.member?(number) == true.
|
426
|
-
#
|
342
|
+
#
|
427
343
|
# Negative or floating point values for `max` are allowed, but may give
|
428
344
|
# surprising results.
|
429
|
-
#
|
345
|
+
#
|
430
346
|
# ```ruby
|
431
347
|
# rand(-100) # => 87
|
432
348
|
# rand(-0.5) # => 0.8130921818028143
|
433
349
|
# rand(1.9) # equivalent to rand(1), which is always 0
|
434
350
|
# ```
|
435
|
-
#
|
351
|
+
#
|
436
352
|
# [\#srand](Kernel.downloaded.ruby_doc#method-i-srand) may be used to
|
437
353
|
# ensure that sequences of random numbers are reproducible between
|
438
354
|
# different runs of a program.
|
439
|
-
#
|
355
|
+
#
|
440
356
|
# See also
|
441
357
|
# [Random\#rand](https://ruby-doc.org/core-2.6.3/Random.html#method-i-rand)
|
442
358
|
# .
|
@@ -468,109 +384,109 @@ module Kernel
|
|
468
384
|
|
469
385
|
# Replaces the current process by running the given external *command* ,
|
470
386
|
# which can take one of the following forms:
|
471
|
-
#
|
387
|
+
#
|
472
388
|
# - `exec(commandline)`
|
473
389
|
# command line string which is passed to the standard shell
|
474
|
-
#
|
390
|
+
#
|
475
391
|
# - `exec(cmdname, arg1, ...)`
|
476
392
|
# command name and one or more arguments (no shell)
|
477
|
-
#
|
393
|
+
#
|
478
394
|
# - `exec([cmdname, argv0], arg1, ...)`
|
479
395
|
# command name, [argv](https://ruby-doc.org/core-2.6.3/0) and zero or
|
480
396
|
# more arguments (no shell)
|
481
|
-
#
|
397
|
+
#
|
482
398
|
# In the first form, the string is taken as a command line that is subject
|
483
399
|
# to shell expansion before being executed.
|
484
|
-
#
|
400
|
+
#
|
485
401
|
# The standard shell always means `"/bin/sh"` on Unix-like systems, same
|
486
402
|
# as `ENV["RUBYSHELL"]` (or `ENV["COMSPEC"]` on Windows NT series), and
|
487
403
|
# similar.
|
488
|
-
#
|
404
|
+
#
|
489
405
|
# If the string from the first form ( `exec("command")` ) follows these
|
490
406
|
# simple rules:
|
491
|
-
#
|
407
|
+
#
|
492
408
|
# - no meta characters
|
493
|
-
#
|
409
|
+
#
|
494
410
|
# - no shell reserved word and no special built-in
|
495
|
-
#
|
411
|
+
#
|
496
412
|
# - Ruby invokes the command directly without shell
|
497
|
-
#
|
413
|
+
#
|
498
414
|
# You can force shell invocation by adding “;” to the string (because “;”
|
499
415
|
# is a meta character).
|
500
|
-
#
|
416
|
+
#
|
501
417
|
# Note that this behavior is observable by pid obtained (return value of
|
502
418
|
# spawn() and
|
503
419
|
# [IO\#pid](https://ruby-doc.org/core-2.6.3/IO.html#method-i-pid) for
|
504
420
|
# [IO.popen](https://ruby-doc.org/core-2.6.3/IO.html#method-c-popen) ) is
|
505
421
|
# the pid of the invoked command, not shell.
|
506
|
-
#
|
422
|
+
#
|
507
423
|
# In the second form ( `exec("command1", "arg1", ...)` ), the first is
|
508
424
|
# taken as a command name and the rest are passed as parameters to command
|
509
425
|
# with no shell expansion.
|
510
|
-
#
|
426
|
+
#
|
511
427
|
# In the third form ( `exec(["command", "argv0"], "arg1", ...)` ),
|
512
428
|
# starting a two-element array at the beginning of the command, the first
|
513
429
|
# element is the command to be executed, and the second argument is used
|
514
430
|
# as the `argv[0]` value, which may show up in process listings.
|
515
|
-
#
|
431
|
+
#
|
516
432
|
# In order to execute the command, one of the `exec(2)` system calls are
|
517
433
|
# used, so the running command may inherit some of the environment of the
|
518
434
|
# original program (including open file descriptors).
|
519
|
-
#
|
435
|
+
#
|
520
436
|
# This behavior is modified by the given `env` and `options` parameters.
|
521
437
|
# See ::spawn for details.
|
522
|
-
#
|
438
|
+
#
|
523
439
|
# If the command fails to execute (typically `Errno::ENOENT` when it was
|
524
440
|
# not found) a
|
525
441
|
# [SystemCallError](https://ruby-doc.org/core-2.6.3/SystemCallError.html)
|
526
442
|
# exception is raised.
|
527
|
-
#
|
443
|
+
#
|
528
444
|
# This method modifies process attributes according to given `options`
|
529
445
|
# before `exec(2)` system call. See ::spawn for more details about the
|
530
446
|
# given `options` .
|
531
|
-
#
|
447
|
+
#
|
532
448
|
# The modified attributes may be retained when `exec(2)` system call
|
533
449
|
# fails.
|
534
|
-
#
|
450
|
+
#
|
535
451
|
# For example, hard resource limits are not restorable.
|
536
|
-
#
|
452
|
+
#
|
537
453
|
# Consider to create a child process using ::spawn or
|
538
454
|
# [\#system](Kernel.downloaded.ruby_doc#method-i-system) if this is not
|
539
455
|
# acceptable.
|
540
|
-
#
|
456
|
+
#
|
541
457
|
# ```ruby
|
542
458
|
# exec "echo *" # echoes list of files in current directory
|
543
459
|
# # never get here
|
544
|
-
#
|
460
|
+
#
|
545
461
|
# exec "echo", "*" # echoes an asterisk
|
546
462
|
# # never get here
|
547
463
|
# ```
|
548
464
|
def exec: (*String args) -> bot
|
549
465
|
|
550
466
|
# Executes *command…* in a subshell. *command…* is one of following forms.
|
551
|
-
#
|
467
|
+
#
|
552
468
|
# commandline : command line string which is passed to the standard shell
|
553
469
|
# cmdname, arg1, ... : command name and one or more arguments (no shell)
|
554
470
|
# [cmdname, argv0], arg1, ... : command name, argv[0] and zero or more arguments (no shell)
|
555
|
-
#
|
471
|
+
#
|
556
472
|
# system returns `true` if the command gives zero exit status, `false` for
|
557
473
|
# non zero exit status. Returns `nil` if command execution fails. An error
|
558
474
|
# status is available in `$?` . The arguments are processed in the same
|
559
475
|
# way as for `Kernel.spawn` .
|
560
|
-
#
|
476
|
+
#
|
561
477
|
# The hash arguments, env and options, are same as `exec` and `spawn` .
|
562
478
|
# See `Kernel.spawn` for details.
|
563
|
-
#
|
479
|
+
#
|
564
480
|
# ```ruby
|
565
481
|
# system("echo *")
|
566
482
|
# system("echo", "*")
|
567
483
|
# ```
|
568
|
-
#
|
484
|
+
#
|
569
485
|
# *produces:*
|
570
|
-
#
|
486
|
+
#
|
571
487
|
# config.h main.rb
|
572
488
|
# *
|
573
|
-
#
|
489
|
+
#
|
574
490
|
# See `Kernel.exec` for the standard shell.
|
575
491
|
def system: (*String args) -> (NilClass | FalseClass | TrueClass)
|
576
492
|
end
|