rbs 3.7.0 → 3.8.0.pre.1
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 +3 -3
- data/.github/workflows/ruby.yml +7 -7
- data/CHANGELOG.md +52 -0
- data/core/array.rbs +1743 -1580
- data/core/basic_object.rbs +38 -35
- data/core/comparable.rbs +1 -1
- data/core/complex.rbs +165 -93
- data/core/data.rbs +1 -1
- data/core/dir.rbs +1 -17
- data/core/encoding.rbs +12 -6
- data/core/enumerable.rbs +270 -266
- data/core/enumerator.rbs +0 -2
- data/core/env.rbs +1 -1
- data/core/errno.rbs +33 -16
- data/core/errors.rbs +2 -2
- data/core/exception.rbs +236 -170
- data/core/fiber.rbs +3 -2
- data/core/file.rbs +32 -74
- data/core/float.rbs +125 -72
- data/core/gc.rbs +138 -40
- data/core/hash.rbs +120 -141
- data/core/integer.rbs +79 -50
- data/core/io/buffer.rbs +49 -43
- data/core/io.rbs +97 -144
- data/core/kernel.rbs +290 -200
- data/core/match_data.rbs +76 -2
- data/core/math.rbs +0 -36
- data/core/module.rbs +28 -23
- data/core/nil_class.rbs +0 -3
- data/core/numeric.rbs +100 -103
- data/core/object.rbs +0 -4
- data/core/object_space/weak_key_map.rbs +3 -4
- data/core/object_space.rbs +3 -3
- data/core/proc.rbs +0 -2
- data/core/process.rbs +109 -57
- data/core/ractor.rbs +37 -4
- data/core/range.rbs +114 -87
- data/core/rational.rbs +0 -2
- data/core/rbs/unnamed/argf.rbs +234 -33
- data/core/rbs/unnamed/env_class.rbs +35 -53
- data/core/rbs/unnamed/random.rbs +1 -2
- data/core/regexp.rbs +4 -52
- data/core/ruby_vm.rbs +88 -9
- data/core/rubygems/config_file.rbs +3 -0
- data/core/rubygems/errors.rbs +0 -5
- data/core/rubygems/platform.rbs +0 -9
- data/core/rubygems/rubygems.rbs +0 -5
- data/core/rubygems/version.rbs +6 -6
- data/core/set.rbs +3 -15
- data/core/string.rbs +130 -136
- data/core/struct.rbs +6 -18
- data/core/symbol.rbs +14 -21
- data/core/thread.rbs +32 -35
- data/core/time.rbs +127 -50
- data/core/trace_point.rbs +16 -0
- data/core/true_class.rbs +0 -1
- data/core/warning.rbs +9 -2
- data/docs/architecture.md +1 -1
- data/docs/syntax.md +1 -1
- data/ext/rbs_extension/location.c +29 -19
- data/ext/rbs_extension/parser.c +267 -292
- data/ext/rbs_extension/parserstate.c +56 -22
- data/lib/rbs/annotate/annotations.rb +3 -3
- data/lib/rbs/annotate/rdoc_source.rb +2 -2
- data/lib/rbs/cli/diff.rb +3 -3
- data/lib/rbs/cli/validate.rb +1 -1
- data/lib/rbs/cli.rb +13 -13
- data/lib/rbs/collection/config.rb +3 -1
- data/lib/rbs/definition_builder/ancestor_builder.rb +3 -3
- data/lib/rbs/environment_loader.rb +1 -1
- data/lib/rbs/namespace.rb +1 -0
- data/lib/rbs/parser_aux.rb +2 -2
- data/lib/rbs/prototype/rb.rb +11 -8
- data/lib/rbs/prototype/rbi.rb +9 -5
- data/lib/rbs/prototype/runtime/value_object_generator.rb +7 -5
- data/lib/rbs/prototype/runtime.rb +4 -5
- data/lib/rbs/type_name.rb +14 -9
- data/lib/rbs/unit_test/type_assertions.rb +2 -2
- data/lib/rbs/validator.rb +3 -1
- data/lib/rbs/version.rb +1 -1
- data/lib/rdoc_plugin/parser.rb +2 -2
- data/rbs.gemspec +4 -0
- data/sig/ancestor_graph.rbs +4 -4
- data/sig/namespace.rbs +2 -3
- data/sig/resolver/constant_resolver.rbs +2 -2
- data/sig/resolver/context.rbs +1 -1
- data/sig/type_alias_regularity.rbs +5 -5
- data/sig/typename.rbs +8 -5
- data/sig/use_map.rbs +1 -1
- data/sig/validator.rbs +2 -2
- data/stdlib/base64/0/base64.rbs +0 -9
- data/stdlib/benchmark/0/benchmark.rbs +11 -2
- data/stdlib/bigdecimal/0/big_decimal.rbs +26 -182
- data/stdlib/cgi/0/core.rbs +47 -0
- data/stdlib/coverage/0/coverage.rbs +0 -3
- data/stdlib/csv/0/csv.rbs +18 -58
- data/stdlib/date/0/date.rbs +4 -19
- data/stdlib/did_you_mean/0/did_you_mean.rbs +0 -5
- data/stdlib/digest/0/digest.rbs +25 -2
- data/stdlib/erb/0/erb.rbs +0 -1
- data/stdlib/etc/0/etc.rbs +51 -34
- data/stdlib/fileutils/0/fileutils.rbs +3 -44
- data/stdlib/io-console/0/io-console.rbs +69 -15
- data/stdlib/ipaddr/0/ipaddr.rbs +8 -4
- data/stdlib/json/0/json.rbs +56 -71
- data/stdlib/logger/0/log_device.rbs +1 -1
- data/stdlib/logger/0/logger.rbs +3 -18
- data/stdlib/net-http/0/net-http.rbs +19 -77
- data/stdlib/nkf/0/nkf.rbs +30 -0
- data/stdlib/objspace/0/objspace.rbs +1 -2
- data/stdlib/observable/0/observable.rbs +1 -1
- data/stdlib/open-uri/0/open-uri.rbs +52 -0
- data/stdlib/open3/0/open3.rbs +0 -8
- data/stdlib/openssl/0/openssl.rbs +136 -69
- data/stdlib/optparse/0/optparse.rbs +58 -18
- data/stdlib/pathname/0/pathname.rbs +2 -8
- data/stdlib/pp/0/pp.rbs +3 -1
- data/stdlib/prettyprint/0/prettyprint.rbs +0 -4
- data/stdlib/pstore/0/pstore.rbs +0 -6
- data/stdlib/psych/0/psych.rbs +15 -4
- data/stdlib/pty/0/pty.rbs +46 -4
- data/stdlib/rdoc/0/code_object.rbs +0 -4
- data/stdlib/rdoc/0/markup.rbs +10 -12
- data/stdlib/rdoc/0/rdoc.rbs +1 -2
- data/stdlib/resolv/0/resolv.rbs +8 -3
- data/stdlib/ripper/0/ripper.rbs +0 -2
- data/stdlib/securerandom/0/securerandom.rbs +0 -2
- data/stdlib/shellwords/0/shellwords.rbs +11 -12
- data/stdlib/singleton/0/singleton.rbs +0 -1
- data/stdlib/socket/0/addrinfo.rbs +0 -1
- data/stdlib/socket/0/basic_socket.rbs +0 -5
- data/stdlib/socket/0/socket.rbs +49 -25
- data/stdlib/socket/0/tcp_server.rbs +0 -3
- data/stdlib/socket/0/tcp_socket.rbs +58 -3
- data/stdlib/socket/0/udp_socket.rbs +0 -1
- data/stdlib/socket/0/unix_server.rbs +0 -3
- data/stdlib/strscan/0/string_scanner.rbs +1265 -422
- data/stdlib/tempfile/0/tempfile.rbs +135 -28
- data/stdlib/time/0/time.rbs +48 -35
- data/stdlib/timeout/0/timeout.rbs +11 -8
- data/stdlib/tmpdir/0/tmpdir.rbs +8 -1
- data/stdlib/tsort/0/tsort.rbs +0 -4
- data/stdlib/uri/0/common.rbs +11 -30
- data/stdlib/uri/0/ftp.rbs +1 -1
- data/stdlib/uri/0/generic.rbs +22 -18
- data/stdlib/uri/0/http.rbs +2 -2
- data/stdlib/uri/0/rfc2396_parser.rbs +3 -0
- data/stdlib/zlib/0/buf_error.rbs +1 -70
- data/stdlib/zlib/0/data_error.rbs +1 -70
- data/stdlib/zlib/0/deflate.rbs +8 -72
- data/stdlib/zlib/0/error.rbs +1 -70
- data/stdlib/zlib/0/gzip_file/crc_error.rbs +2 -105
- data/stdlib/zlib/0/gzip_file/error.rbs +2 -105
- data/stdlib/zlib/0/gzip_file/length_error.rbs +2 -105
- data/stdlib/zlib/0/gzip_file/no_footer.rbs +2 -105
- data/stdlib/zlib/0/gzip_file.rbs +1 -71
- data/stdlib/zlib/0/gzip_reader.rbs +3 -74
- data/stdlib/zlib/0/gzip_writer.rbs +1 -70
- data/stdlib/zlib/0/inflate.rbs +4 -71
- data/stdlib/zlib/0/mem_error.rbs +1 -70
- data/stdlib/zlib/0/need_dict.rbs +1 -70
- data/stdlib/zlib/0/stream_end.rbs +1 -70
- data/stdlib/zlib/0/stream_error.rbs +1 -70
- data/stdlib/zlib/0/version_error.rbs +1 -70
- data/stdlib/zlib/0/zlib.rbs +0 -2
- data/stdlib/zlib/0/zstream.rbs +4 -72
- metadata +4 -6
data/core/kernel.rbs
CHANGED
|
@@ -25,7 +25,6 @@
|
|
|
25
25
|
# * [Random Values](rdoc-ref:Kernel@Random+Values)
|
|
26
26
|
# * [Other](rdoc-ref:Kernel@Other)
|
|
27
27
|
#
|
|
28
|
-
#
|
|
29
28
|
# ### Converting
|
|
30
29
|
#
|
|
31
30
|
# * #Array: Returns an Array based on the given argument.
|
|
@@ -36,7 +35,6 @@
|
|
|
36
35
|
# * #Rational: Returns a Rational based on the given arguments.
|
|
37
36
|
# * #String: Returns a String based on the given argument.
|
|
38
37
|
#
|
|
39
|
-
#
|
|
40
38
|
# ### Querying
|
|
41
39
|
#
|
|
42
40
|
# * #__callee__: Returns the called name of the current method as a symbol.
|
|
@@ -56,7 +54,6 @@
|
|
|
56
54
|
# * #local_variables: Returns an array of local variables as symbols.
|
|
57
55
|
# * #test: Performs specified tests on the given single file or pair of files.
|
|
58
56
|
#
|
|
59
|
-
#
|
|
60
57
|
# ### Exiting
|
|
61
58
|
#
|
|
62
59
|
# * #abort: Exits the current process after printing the given arguments.
|
|
@@ -66,7 +63,6 @@
|
|
|
66
63
|
# * #exit!: Exits the current process without calling any registered `at_exit`
|
|
67
64
|
# handlers.
|
|
68
65
|
#
|
|
69
|
-
#
|
|
70
66
|
# ### Exceptions
|
|
71
67
|
#
|
|
72
68
|
# * #catch: Executes the given block, possibly catching a thrown object.
|
|
@@ -74,7 +70,6 @@
|
|
|
74
70
|
# arguments.
|
|
75
71
|
# * #throw: Returns from the active catch block waiting for the given tag.
|
|
76
72
|
#
|
|
77
|
-
#
|
|
78
73
|
# ### IO
|
|
79
74
|
#
|
|
80
75
|
# * ::pp: Prints the given objects in pretty form.
|
|
@@ -92,13 +87,11 @@
|
|
|
92
87
|
# input.
|
|
93
88
|
# * #select: Same as IO.select.
|
|
94
89
|
#
|
|
95
|
-
#
|
|
96
90
|
# ### Procs
|
|
97
91
|
#
|
|
98
92
|
# * #lambda: Returns a lambda proc for the given block.
|
|
99
93
|
# * #proc: Returns a new Proc; equivalent to Proc.new.
|
|
100
94
|
#
|
|
101
|
-
#
|
|
102
95
|
# ### Tracing
|
|
103
96
|
#
|
|
104
97
|
# * #set_trace_func: Sets the given proc as the handler for tracing, or
|
|
@@ -107,7 +100,6 @@
|
|
|
107
100
|
# * #untrace_var: Disables tracing of assignments to the given global
|
|
108
101
|
# variable.
|
|
109
102
|
#
|
|
110
|
-
#
|
|
111
103
|
# ### Subprocesses
|
|
112
104
|
#
|
|
113
105
|
# * [\`command`](rdoc-ref:Kernel#`): Returns the standard output of running
|
|
@@ -118,7 +110,6 @@
|
|
|
118
110
|
# completion.
|
|
119
111
|
# * #system: Executes the given command in a subshell.
|
|
120
112
|
#
|
|
121
|
-
#
|
|
122
113
|
# ### Loading
|
|
123
114
|
#
|
|
124
115
|
# * #autoload: Registers the given file to be loaded when the given constant
|
|
@@ -128,21 +119,18 @@
|
|
|
128
119
|
# * #require_relative: Loads the Ruby file path relative to the calling file,
|
|
129
120
|
# unless it has already been loaded.
|
|
130
121
|
#
|
|
131
|
-
#
|
|
132
122
|
# ### Yielding
|
|
133
123
|
#
|
|
134
124
|
# * #tap: Yields `self` to the given block; returns `self`.
|
|
135
125
|
# * #then (aliased as #yield_self): Yields `self` to the block and returns the
|
|
136
126
|
# result of the block.
|
|
137
127
|
#
|
|
138
|
-
#
|
|
139
128
|
# ### Random Values
|
|
140
129
|
#
|
|
141
130
|
# * #rand: Returns a pseudo-random floating point number strictly between 0.0
|
|
142
131
|
# and 1.0.
|
|
143
132
|
# * #srand: Seeds the pseudo-random number generator with the given number.
|
|
144
133
|
#
|
|
145
|
-
#
|
|
146
134
|
# ### Other
|
|
147
135
|
#
|
|
148
136
|
# * #eval: Evaluates the given string as Ruby code.
|
|
@@ -387,7 +375,6 @@ module Kernel : BasicObject
|
|
|
387
375
|
# * Once in the parent process, returning the pid of the child process.
|
|
388
376
|
# * Once in the child process, returning `nil`.
|
|
389
377
|
#
|
|
390
|
-
#
|
|
391
378
|
# Example:
|
|
392
379
|
#
|
|
393
380
|
# puts "This is the first line before the fork (pid #{Process.pid})"
|
|
@@ -410,7 +397,6 @@ module Kernel : BasicObject
|
|
|
410
397
|
# * Process.wait, to collect the termination statuses of its children.
|
|
411
398
|
# * Process.detach, to register disinterest in their status.
|
|
412
399
|
#
|
|
413
|
-
#
|
|
414
400
|
# The thread calling `fork` is the only thread in the created child process;
|
|
415
401
|
# `fork` doesn't copy other threads.
|
|
416
402
|
#
|
|
@@ -482,7 +468,6 @@ module Kernel : BasicObject
|
|
|
482
468
|
# Complex('+1i') # => (0+1i)
|
|
483
469
|
# Complex('-1i') # => (0-1i)
|
|
484
470
|
#
|
|
485
|
-
#
|
|
486
471
|
# * At-sign separated real and imaginary rational substrings, each of which
|
|
487
472
|
# specifies a Rational value, specifying [polar
|
|
488
473
|
# coordinates](rdoc-ref:Complex@Polar+Coordinates):
|
|
@@ -504,9 +489,9 @@ module Kernel : BasicObject
|
|
|
504
489
|
# - Float(arg, exception: true) -> float or nil
|
|
505
490
|
# -->
|
|
506
491
|
# Returns *arg* converted to a float. Numeric types are converted directly, and
|
|
507
|
-
# with exception to String and `nil
|
|
508
|
-
# Converting a String with invalid characters will result in
|
|
509
|
-
# Converting `nil` generates a TypeError.
|
|
492
|
+
# with exception to String and `nil`, the rest are converted using *arg*`.to_f`.
|
|
493
|
+
# Converting a String with invalid characters will result in an ArgumentError.
|
|
494
|
+
# Converting `nil` generates a TypeError. Exceptions can be suppressed by
|
|
510
495
|
# passing `exception: false`.
|
|
511
496
|
#
|
|
512
497
|
# Float(1) #=> 1.0
|
|
@@ -530,11 +515,9 @@ module Kernel : BasicObject
|
|
|
530
515
|
# * A hash, returns `object`.
|
|
531
516
|
# * An empty array or `nil`, returns an empty hash.
|
|
532
517
|
#
|
|
533
|
-
#
|
|
534
518
|
# * Otherwise, if `object.to_hash` returns a hash, returns that hash.
|
|
535
519
|
# * Otherwise, returns TypeError.
|
|
536
520
|
#
|
|
537
|
-
#
|
|
538
521
|
# Examples:
|
|
539
522
|
#
|
|
540
523
|
# Hash({foo: 0, bar: 1}) # => {:foo=>0, :bar=>1}
|
|
@@ -555,22 +538,22 @@ module Kernel : BasicObject
|
|
|
555
538
|
#
|
|
556
539
|
# With a non-zero `base`, `object` must be a string or convertible to a string.
|
|
557
540
|
#
|
|
558
|
-
# ####
|
|
541
|
+
# #### Numeric objects
|
|
559
542
|
#
|
|
560
|
-
# With integer argument `object` given, returns `object`:
|
|
543
|
+
# With an integer argument `object` given, returns `object`:
|
|
561
544
|
#
|
|
562
545
|
# Integer(1) # => 1
|
|
563
546
|
# Integer(-1) # => -1
|
|
564
547
|
#
|
|
565
|
-
# With floating-point argument `object` given, returns `object` truncated to
|
|
566
|
-
# integer:
|
|
548
|
+
# With a floating-point argument `object` given, returns `object` truncated to
|
|
549
|
+
# an integer:
|
|
567
550
|
#
|
|
568
551
|
# Integer(1.9) # => 1 # Rounds toward zero.
|
|
569
552
|
# Integer(-1.9) # => -1 # Rounds toward zero.
|
|
570
553
|
#
|
|
571
|
-
# ####
|
|
554
|
+
# #### String objects
|
|
572
555
|
#
|
|
573
|
-
# With string argument `object` and zero `base` given, returns `object`
|
|
556
|
+
# With a string argument `object` and zero `base` given, returns `object`
|
|
574
557
|
# converted to an integer in base 10:
|
|
575
558
|
#
|
|
576
559
|
# Integer('100') # => 100
|
|
@@ -580,7 +563,7 @@ module Kernel : BasicObject
|
|
|
580
563
|
# the actual base (radix indicator):
|
|
581
564
|
#
|
|
582
565
|
# Integer('0100') # => 64 # Leading '0' specifies base 8.
|
|
583
|
-
# Integer('0b100') # => 4 # Leading '0b'
|
|
566
|
+
# Integer('0b100') # => 4 # Leading '0b' specifies base 2.
|
|
584
567
|
# Integer('0x100') # => 256 # Leading '0x' specifies base 16.
|
|
585
568
|
#
|
|
586
569
|
# With a positive `base` (in range 2..36) given, returns `object` converted to
|
|
@@ -591,7 +574,7 @@ module Kernel : BasicObject
|
|
|
591
574
|
# Integer('-100', 16) # => -256
|
|
592
575
|
#
|
|
593
576
|
# With a negative `base` (in range -36..-2) given, returns `object` converted to
|
|
594
|
-
#
|
|
577
|
+
# the radix indicator if it exists or `base`:
|
|
595
578
|
#
|
|
596
579
|
# Integer('0x100', -2) # => 256
|
|
597
580
|
# Integer('100', -2) # => 4
|
|
@@ -600,7 +583,7 @@ module Kernel : BasicObject
|
|
|
600
583
|
# Integer('0o100', -10) # => 64
|
|
601
584
|
# Integer('100', -10) # => 100
|
|
602
585
|
#
|
|
603
|
-
# `base` -1 is
|
|
586
|
+
# `base` -1 is equivalent to the -10 case.
|
|
604
587
|
#
|
|
605
588
|
# When converting strings, surrounding whitespace and embedded underscores are
|
|
606
589
|
# allowed and ignored:
|
|
@@ -608,7 +591,7 @@ module Kernel : BasicObject
|
|
|
608
591
|
# Integer(' 100 ') # => 100
|
|
609
592
|
# Integer('-1_0_0', 16) # => -256
|
|
610
593
|
#
|
|
611
|
-
# ####
|
|
594
|
+
# #### Other classes
|
|
612
595
|
#
|
|
613
596
|
# Examples with `object` of various other classes:
|
|
614
597
|
#
|
|
@@ -616,14 +599,13 @@ module Kernel : BasicObject
|
|
|
616
599
|
# Integer(Complex(2, 0)) # => 2 # Imaginary part must be zero.
|
|
617
600
|
# Integer(Time.now) # => 1650974042
|
|
618
601
|
#
|
|
619
|
-
# ####
|
|
602
|
+
# #### Keywords
|
|
620
603
|
#
|
|
621
|
-
# With optional keyword argument `exception` given as `true` (the default):
|
|
604
|
+
# With the optional keyword argument `exception` given as `true` (the default):
|
|
622
605
|
#
|
|
623
606
|
# * Raises TypeError if `object` does not respond to `to_int` or `to_i`.
|
|
624
607
|
# * Raises TypeError if `object` is `nil`.
|
|
625
|
-
# *
|
|
626
|
-
#
|
|
608
|
+
# * Raises ArgumentError if `object` is an invalid string.
|
|
627
609
|
#
|
|
628
610
|
# With `exception` given as `false`, an exception of any kind is suppressed and
|
|
629
611
|
# `nil` is returned.
|
|
@@ -787,11 +769,10 @@ module Kernel : BasicObject
|
|
|
787
769
|
# rdoc-file=load.c
|
|
788
770
|
# - autoload(const, filename) -> nil
|
|
789
771
|
# -->
|
|
790
|
-
# Registers
|
|
791
|
-
#
|
|
792
|
-
# a symbol) is accessed.
|
|
772
|
+
# Registers *filename* to be loaded (using Kernel::require) the first time that
|
|
773
|
+
# *const* (which may be a String or a symbol) is accessed.
|
|
793
774
|
#
|
|
794
|
-
#
|
|
775
|
+
# autoload(:MyModule, "/usr/local/lib/modules/my_module.rb")
|
|
795
776
|
#
|
|
796
777
|
# If *const* is defined as autoload, the file name to be loaded is replaced with
|
|
797
778
|
# *filename*. If *const* is defined but not as autoload, does nothing.
|
|
@@ -802,11 +783,24 @@ module Kernel : BasicObject
|
|
|
802
783
|
# rdoc-file=load.c
|
|
803
784
|
# - autoload?(name, inherit=true) -> String or nil
|
|
804
785
|
# -->
|
|
805
|
-
# Returns *filename* to be loaded if *name* is registered as `autoload
|
|
786
|
+
# Returns *filename* to be loaded if *name* is registered as `autoload` in the
|
|
787
|
+
# current namespace or one of its ancestors.
|
|
806
788
|
#
|
|
807
789
|
# autoload(:B, "b")
|
|
808
790
|
# autoload?(:B) #=> "b"
|
|
809
791
|
#
|
|
792
|
+
# module C
|
|
793
|
+
# autoload(:D, "d")
|
|
794
|
+
# autoload?(:D) #=> "d"
|
|
795
|
+
# autoload?(:B) #=> nil
|
|
796
|
+
# end
|
|
797
|
+
#
|
|
798
|
+
# class E
|
|
799
|
+
# autoload(:F, "f")
|
|
800
|
+
# autoload?(:F) #=> "f"
|
|
801
|
+
# autoload?(:B) #=> "b"
|
|
802
|
+
# end
|
|
803
|
+
#
|
|
810
804
|
def self?.autoload?: (interned name) -> String?
|
|
811
805
|
|
|
812
806
|
# <!--
|
|
@@ -912,53 +906,165 @@ module Kernel : BasicObject
|
|
|
912
906
|
def self?.exit!: (?int | bool status) -> bot
|
|
913
907
|
|
|
914
908
|
# <!-- rdoc-file=eval.c -->
|
|
915
|
-
#
|
|
916
|
-
#
|
|
917
|
-
#
|
|
918
|
-
#
|
|
919
|
-
#
|
|
920
|
-
#
|
|
921
|
-
#
|
|
922
|
-
#
|
|
923
|
-
#
|
|
924
|
-
#
|
|
925
|
-
#
|
|
926
|
-
#
|
|
927
|
-
#
|
|
928
|
-
#
|
|
929
|
-
#
|
|
930
|
-
#
|
|
909
|
+
# Raises an exception; see [Exceptions](rdoc-ref:exceptions.md).
|
|
910
|
+
#
|
|
911
|
+
# Argument `exception` sets the class of the new exception; it should be class
|
|
912
|
+
# Exception or one of its subclasses (most commonly, RuntimeError or
|
|
913
|
+
# StandardError), or an instance of one of those classes:
|
|
914
|
+
#
|
|
915
|
+
# begin
|
|
916
|
+
# raise(StandardError)
|
|
917
|
+
# rescue => x
|
|
918
|
+
# p x.class
|
|
919
|
+
# end
|
|
920
|
+
# # => StandardError
|
|
921
|
+
#
|
|
922
|
+
# Argument `message` sets the stored message in the new exception, which may be
|
|
923
|
+
# retrieved by method Exception#message; the message must be a
|
|
924
|
+
# [string-convertible
|
|
925
|
+
# object](rdoc-ref:implicit_conversion.rdoc@String-Convertible+Objects) or
|
|
926
|
+
# `nil`:
|
|
927
|
+
#
|
|
928
|
+
# begin
|
|
929
|
+
# raise(StandardError, 'Boom')
|
|
930
|
+
# rescue => x
|
|
931
|
+
# p x.message
|
|
932
|
+
# end
|
|
933
|
+
# # => "Boom"
|
|
934
|
+
#
|
|
935
|
+
# If argument `message` is not given, the message is the exception class name.
|
|
936
|
+
#
|
|
937
|
+
# See [Messages](rdoc-ref:exceptions.md@Messages).
|
|
938
|
+
#
|
|
939
|
+
# Argument `backtrace` sets the stored backtrace in the new exception, which may
|
|
940
|
+
# be retrieved by method Exception#backtrace; the backtrace must be an array of
|
|
941
|
+
# strings or `nil`:
|
|
942
|
+
#
|
|
943
|
+
# begin
|
|
944
|
+
# raise(StandardError, 'Boom', %w[foo bar baz])
|
|
945
|
+
# rescue => x
|
|
946
|
+
# p x.backtrace
|
|
947
|
+
# end
|
|
948
|
+
# # => ["foo", "bar", "baz"]
|
|
949
|
+
#
|
|
950
|
+
# If argument `backtrace` is not given, the backtrace is set according to an
|
|
951
|
+
# array of Thread::Backtrace::Location objects, as derived from the call stack.
|
|
952
|
+
#
|
|
953
|
+
# See [Backtraces](rdoc-ref:exceptions.md@Backtraces).
|
|
954
|
+
#
|
|
955
|
+
# Keyword argument `cause` sets the stored cause in the new exception, which may
|
|
956
|
+
# be retrieved by method Exception#cause; the cause must be an exception object
|
|
957
|
+
# (Exception or one of its subclasses), or `nil`:
|
|
958
|
+
#
|
|
959
|
+
# begin
|
|
960
|
+
# raise(StandardError, cause: RuntimeError.new)
|
|
961
|
+
# rescue => x
|
|
962
|
+
# p x.cause
|
|
963
|
+
# end
|
|
964
|
+
# # => #<RuntimeError: RuntimeError>
|
|
965
|
+
#
|
|
966
|
+
# If keyword argument `cause` is not given, the cause is the value of `$!`.
|
|
967
|
+
#
|
|
968
|
+
# See [Cause](rdoc-ref:exceptions.md@Cause).
|
|
969
|
+
#
|
|
970
|
+
# In the alternate calling sequence, where argument `exception` *not* given,
|
|
971
|
+
# raises a new exception of the class given by `$!`, or of class RuntimeError if
|
|
972
|
+
# `$!` is `nil`:
|
|
973
|
+
#
|
|
974
|
+
# begin
|
|
975
|
+
# raise
|
|
976
|
+
# rescue => x
|
|
977
|
+
# p x
|
|
978
|
+
# end
|
|
979
|
+
# # => RuntimeError
|
|
980
|
+
#
|
|
981
|
+
# With argument `exception` not given, argument `message` and keyword argument
|
|
982
|
+
# `cause` may be given, but argument `backtrace` may not be given.
|
|
931
983
|
#
|
|
932
984
|
def self?.fail: () -> bot
|
|
933
985
|
| (string message, ?cause: Exception?) -> bot
|
|
934
|
-
| (_Exception exception, ?_ToS? message, ?String | Array[String] | nil backtrace, ?cause: Exception?) -> bot
|
|
986
|
+
| (_Exception exception, ?_ToS? message, ?String | Array[String] | Array[Thread::Backtrace::Location] | nil backtrace, ?cause: Exception?) -> bot
|
|
935
987
|
| (_Exception exception, ?cause: Exception?, **untyped) -> bot
|
|
936
988
|
|
|
937
989
|
# <!--
|
|
938
990
|
# rdoc-file=eval.c
|
|
939
|
-
# - raise
|
|
940
|
-
# - raise(
|
|
941
|
-
#
|
|
942
|
-
#
|
|
943
|
-
#
|
|
944
|
-
#
|
|
945
|
-
#
|
|
946
|
-
#
|
|
947
|
-
#
|
|
948
|
-
#
|
|
949
|
-
#
|
|
950
|
-
#
|
|
951
|
-
#
|
|
952
|
-
#
|
|
953
|
-
#
|
|
954
|
-
#
|
|
955
|
-
#
|
|
956
|
-
#
|
|
957
|
-
#
|
|
958
|
-
#
|
|
959
|
-
#
|
|
960
|
-
#
|
|
961
|
-
#
|
|
991
|
+
# - raise(exception, message = exception.to_s, backtrace = nil, cause: $!)
|
|
992
|
+
# - raise(message = nil, cause: $!)
|
|
993
|
+
# -->
|
|
994
|
+
# Raises an exception; see [Exceptions](rdoc-ref:exceptions.md).
|
|
995
|
+
#
|
|
996
|
+
# Argument `exception` sets the class of the new exception; it should be class
|
|
997
|
+
# Exception or one of its subclasses (most commonly, RuntimeError or
|
|
998
|
+
# StandardError), or an instance of one of those classes:
|
|
999
|
+
#
|
|
1000
|
+
# begin
|
|
1001
|
+
# raise(StandardError)
|
|
1002
|
+
# rescue => x
|
|
1003
|
+
# p x.class
|
|
1004
|
+
# end
|
|
1005
|
+
# # => StandardError
|
|
1006
|
+
#
|
|
1007
|
+
# Argument `message` sets the stored message in the new exception, which may be
|
|
1008
|
+
# retrieved by method Exception#message; the message must be a
|
|
1009
|
+
# [string-convertible
|
|
1010
|
+
# object](rdoc-ref:implicit_conversion.rdoc@String-Convertible+Objects) or
|
|
1011
|
+
# `nil`:
|
|
1012
|
+
#
|
|
1013
|
+
# begin
|
|
1014
|
+
# raise(StandardError, 'Boom')
|
|
1015
|
+
# rescue => x
|
|
1016
|
+
# p x.message
|
|
1017
|
+
# end
|
|
1018
|
+
# # => "Boom"
|
|
1019
|
+
#
|
|
1020
|
+
# If argument `message` is not given, the message is the exception class name.
|
|
1021
|
+
#
|
|
1022
|
+
# See [Messages](rdoc-ref:exceptions.md@Messages).
|
|
1023
|
+
#
|
|
1024
|
+
# Argument `backtrace` sets the stored backtrace in the new exception, which may
|
|
1025
|
+
# be retrieved by method Exception#backtrace; the backtrace must be an array of
|
|
1026
|
+
# strings or `nil`:
|
|
1027
|
+
#
|
|
1028
|
+
# begin
|
|
1029
|
+
# raise(StandardError, 'Boom', %w[foo bar baz])
|
|
1030
|
+
# rescue => x
|
|
1031
|
+
# p x.backtrace
|
|
1032
|
+
# end
|
|
1033
|
+
# # => ["foo", "bar", "baz"]
|
|
1034
|
+
#
|
|
1035
|
+
# If argument `backtrace` is not given, the backtrace is set according to an
|
|
1036
|
+
# array of Thread::Backtrace::Location objects, as derived from the call stack.
|
|
1037
|
+
#
|
|
1038
|
+
# See [Backtraces](rdoc-ref:exceptions.md@Backtraces).
|
|
1039
|
+
#
|
|
1040
|
+
# Keyword argument `cause` sets the stored cause in the new exception, which may
|
|
1041
|
+
# be retrieved by method Exception#cause; the cause must be an exception object
|
|
1042
|
+
# (Exception or one of its subclasses), or `nil`:
|
|
1043
|
+
#
|
|
1044
|
+
# begin
|
|
1045
|
+
# raise(StandardError, cause: RuntimeError.new)
|
|
1046
|
+
# rescue => x
|
|
1047
|
+
# p x.cause
|
|
1048
|
+
# end
|
|
1049
|
+
# # => #<RuntimeError: RuntimeError>
|
|
1050
|
+
#
|
|
1051
|
+
# If keyword argument `cause` is not given, the cause is the value of `$!`.
|
|
1052
|
+
#
|
|
1053
|
+
# See [Cause](rdoc-ref:exceptions.md@Cause).
|
|
1054
|
+
#
|
|
1055
|
+
# In the alternate calling sequence, where argument `exception` *not* given,
|
|
1056
|
+
# raises a new exception of the class given by `$!`, or of class RuntimeError if
|
|
1057
|
+
# `$!` is `nil`:
|
|
1058
|
+
#
|
|
1059
|
+
# begin
|
|
1060
|
+
# raise
|
|
1061
|
+
# rescue => x
|
|
1062
|
+
# p x
|
|
1063
|
+
# end
|
|
1064
|
+
# # => RuntimeError
|
|
1065
|
+
#
|
|
1066
|
+
# With argument `exception` not given, argument `message` and keyword argument
|
|
1067
|
+
# `cause` may be given, but argument `backtrace` may not be given.
|
|
962
1068
|
#
|
|
963
1069
|
alias raise fail
|
|
964
1070
|
|
|
@@ -1051,10 +1157,10 @@ module Kernel : BasicObject
|
|
|
1051
1157
|
# will be raised.
|
|
1052
1158
|
#
|
|
1053
1159
|
# If the optional *wrap* parameter is `true`, the loaded script will be executed
|
|
1054
|
-
# under an anonymous module
|
|
1055
|
-
#
|
|
1056
|
-
#
|
|
1057
|
-
#
|
|
1160
|
+
# under an anonymous module. If the optional *wrap* parameter is a module, the
|
|
1161
|
+
# loaded script will be executed under the given module. In no circumstance will
|
|
1162
|
+
# any local variables in the loaded file be propagated to the loading
|
|
1163
|
+
# environment.
|
|
1058
1164
|
#
|
|
1059
1165
|
def self?.load: (String filename, ?Module | bool) -> bool
|
|
1060
1166
|
|
|
@@ -1074,8 +1180,8 @@ module Kernel : BasicObject
|
|
|
1074
1180
|
# # ...
|
|
1075
1181
|
# end
|
|
1076
1182
|
#
|
|
1077
|
-
# StopIteration raised in the block breaks the loop.
|
|
1078
|
-
# the "result" value stored in the exception.
|
|
1183
|
+
# A StopIteration raised in the block breaks the loop. In this case, loop
|
|
1184
|
+
# returns the "result" value stored in the exception.
|
|
1079
1185
|
#
|
|
1080
1186
|
# enum = Enumerator.new { |y|
|
|
1081
1187
|
# y << "one"
|
|
@@ -1135,7 +1241,6 @@ module Kernel : BasicObject
|
|
|
1135
1241
|
# * If not the last object, writes the output field separator
|
|
1136
1242
|
# `$OUTPUT_FIELD_SEPARATOR` (`$,` if it is not `nil`.
|
|
1137
1243
|
#
|
|
1138
|
-
#
|
|
1139
1244
|
# With default separators:
|
|
1140
1245
|
#
|
|
1141
1246
|
# objects = [0, 0.0, Rational(0, 1), Complex(0, 0), :zero, 'zero']
|
|
@@ -1282,7 +1387,7 @@ module Kernel : BasicObject
|
|
|
1282
1387
|
# -->
|
|
1283
1388
|
# prints arguments in pretty form.
|
|
1284
1389
|
#
|
|
1285
|
-
# pp returns argument(s).
|
|
1390
|
+
# `#pp` returns argument(s).
|
|
1286
1391
|
#
|
|
1287
1392
|
def self?.pp: [T] (T arg0) -> T
|
|
1288
1393
|
| (untyped, untyped, *untyped) -> Array[untyped]
|
|
@@ -1382,8 +1487,8 @@ module Kernel : BasicObject
|
|
|
1382
1487
|
# $cat t.txt | ruby -e "p readlines 12"
|
|
1383
1488
|
# ["First line\n", "Second line\n", "\n", "Fourth line\n", "Fifth line\n"]
|
|
1384
1489
|
#
|
|
1385
|
-
# With arguments `sep` and `limit` given, combines the two behaviors
|
|
1386
|
-
# Separator and Line Limit](rdoc-ref:IO@Line+Separator+and+Line+Limit).
|
|
1490
|
+
# With arguments `sep` and `limit` given, combines the two behaviors (see [Line
|
|
1491
|
+
# Separator and Line Limit](rdoc-ref:IO@Line+Separator+and+Line+Limit)).
|
|
1387
1492
|
#
|
|
1388
1493
|
# Optional keyword argument `chomp` specifies whether line separators are to be
|
|
1389
1494
|
# omitted:
|
|
@@ -1408,7 +1513,6 @@ module Kernel : BasicObject
|
|
|
1408
1513
|
# * Otherwise, installed gems are searched for a file that matches. If it's
|
|
1409
1514
|
# found in gem 'y', that gem is activated (added to the loadpath).
|
|
1410
1515
|
#
|
|
1411
|
-
#
|
|
1412
1516
|
# The normal `require` functionality of returning false if that file has already
|
|
1413
1517
|
# been loaded is preserved.
|
|
1414
1518
|
#
|
|
@@ -1438,7 +1542,8 @@ module Kernel : BasicObject
|
|
|
1438
1542
|
# Each of the arguments `read_ios`, `write_ios`, and `error_ios` is an array of
|
|
1439
1543
|
# IO objects.
|
|
1440
1544
|
#
|
|
1441
|
-
# Argument `timeout` is
|
|
1545
|
+
# Argument `timeout` is a numeric value (such as integer or float) timeout
|
|
1546
|
+
# interval in seconds.
|
|
1442
1547
|
#
|
|
1443
1548
|
# The method monitors the IO objects given in all three arrays, waiting for some
|
|
1444
1549
|
# to be ready; returns a 3-element array whose elements are:
|
|
@@ -1447,7 +1552,6 @@ module Kernel : BasicObject
|
|
|
1447
1552
|
# * An array of the objects in `write_ios` that are ready for writing.
|
|
1448
1553
|
# * An array of the objects in `error_ios` have pending exceptions.
|
|
1449
1554
|
#
|
|
1450
|
-
#
|
|
1451
1555
|
# If no object becomes ready within the given `timeout`, `nil` is returned.
|
|
1452
1556
|
#
|
|
1453
1557
|
# IO.select peeks the buffer of IO objects for testing readability. If the IO
|
|
@@ -1616,59 +1720,69 @@ module Kernel : BasicObject
|
|
|
1616
1720
|
|
|
1617
1721
|
# <!--
|
|
1618
1722
|
# rdoc-file=file.c
|
|
1619
|
-
# - test(
|
|
1620
|
-
# -->
|
|
1621
|
-
#
|
|
1622
|
-
#
|
|
1623
|
-
#
|
|
1624
|
-
#
|
|
1625
|
-
#
|
|
1626
|
-
#
|
|
1627
|
-
#
|
|
1628
|
-
#
|
|
1629
|
-
#
|
|
1630
|
-
#
|
|
1631
|
-
#
|
|
1632
|
-
#
|
|
1633
|
-
#
|
|
1634
|
-
#
|
|
1635
|
-
#
|
|
1636
|
-
#
|
|
1637
|
-
#
|
|
1638
|
-
#
|
|
1639
|
-
#
|
|
1640
|
-
#
|
|
1641
|
-
#
|
|
1642
|
-
#
|
|
1643
|
-
#
|
|
1644
|
-
#
|
|
1645
|
-
#
|
|
1646
|
-
#
|
|
1647
|
-
#
|
|
1648
|
-
#
|
|
1649
|
-
#
|
|
1650
|
-
#
|
|
1651
|
-
#
|
|
1652
|
-
#
|
|
1653
|
-
#
|
|
1654
|
-
#
|
|
1655
|
-
#
|
|
1656
|
-
#
|
|
1657
|
-
#
|
|
1658
|
-
#
|
|
1659
|
-
#
|
|
1660
|
-
#
|
|
1661
|
-
#
|
|
1662
|
-
#
|
|
1663
|
-
#
|
|
1664
|
-
#
|
|
1665
|
-
#
|
|
1666
|
-
#
|
|
1667
|
-
#
|
|
1668
|
-
#
|
|
1669
|
-
#
|
|
1670
|
-
#
|
|
1671
|
-
#
|
|
1723
|
+
# - test(char, path0, path1 = nil) -> object
|
|
1724
|
+
# -->
|
|
1725
|
+
# Performs a test on one or both of the *filesystem entities* at the given paths
|
|
1726
|
+
# `path0` and `path1`:
|
|
1727
|
+
# * Each path `path0` or `path1` points to a file, directory, device, pipe,
|
|
1728
|
+
# etc.
|
|
1729
|
+
# * Character `char` selects a specific test.
|
|
1730
|
+
# The tests:
|
|
1731
|
+
# * Each of these tests operates only on the entity at `path0`,
|
|
1732
|
+
# and returns `true` or `false`;
|
|
1733
|
+
# for a non-existent entity, returns `false` (does not raise exception):
|
|
1734
|
+
# Character |Test
|
|
1735
|
+
# ------------|-------------------------------------------------------------------------
|
|
1736
|
+
# <tt>'b'</tt>|Whether the entity is a block device.
|
|
1737
|
+
# <tt>'c'</tt>|Whether the entity is a character device.
|
|
1738
|
+
# <tt>'d'</tt>|Whether the entity is a directory.
|
|
1739
|
+
# <tt>'e'</tt>|Whether the entity is an existing entity.
|
|
1740
|
+
# <tt>'f'</tt>|Whether the entity is an existing regular file.
|
|
1741
|
+
# <tt>'g'</tt>|Whether the entity's setgid bit is set.
|
|
1742
|
+
# <tt>'G'</tt>|Whether the entity's group ownership is equal to the caller's.
|
|
1743
|
+
# <tt>'k'</tt>|Whether the entity's sticky bit is set.
|
|
1744
|
+
# <tt>'l'</tt>|Whether the entity is a symbolic link.
|
|
1745
|
+
# <tt>'o'</tt>|Whether the entity is owned by the caller's effective uid.
|
|
1746
|
+
# <tt>'O'</tt>|Like <tt>'o'</tt>, but uses the real uid (not the effective uid).
|
|
1747
|
+
# <tt>'p'</tt>|Whether the entity is a FIFO device (named pipe).
|
|
1748
|
+
# <tt>'r'</tt>|Whether the entity is readable by the caller's effective uid/gid.
|
|
1749
|
+
# <tt>'R'</tt>|Like <tt>'r'</tt>, but uses the real uid/gid (not the effective uid/gid).
|
|
1750
|
+
# <tt>'S'</tt>|Whether the entity is a socket.
|
|
1751
|
+
# <tt>'u'</tt>|Whether the entity's setuid bit is set.
|
|
1752
|
+
# <tt>'w'</tt>|Whether the entity is writable by the caller's effective uid/gid.
|
|
1753
|
+
# <tt>'W'</tt>|Like <tt>'w'</tt>, but uses the real uid/gid (not the effective uid/gid).
|
|
1754
|
+
# <tt>'x'</tt>|Whether the entity is executable by the caller's effective uid/gid.
|
|
1755
|
+
# <tt>'X'</tt>|Like <tt>'x'</tt>, but uses the real uid/gid (not the effective uid/git).
|
|
1756
|
+
# <tt>'z'</tt>|Whether the entity exists and is of length zero.
|
|
1757
|
+
# * This test operates only on the entity at `path0`,
|
|
1758
|
+
# and returns an integer size or `nil`:
|
|
1759
|
+
# Character |Test
|
|
1760
|
+
# ------------|--------------------------------------------------------------------------------------------
|
|
1761
|
+
# <tt>'s'</tt>|Returns positive integer size if the entity exists and has non-zero length, +nil+ otherwise.
|
|
1762
|
+
# * Each of these tests operates only on the entity at `path0`,
|
|
1763
|
+
# and returns a Time object;
|
|
1764
|
+
# raises an exception if the entity does not exist:
|
|
1765
|
+
# Character |Test
|
|
1766
|
+
# ------------|--------------------------------------
|
|
1767
|
+
# <tt>'A'</tt>|Last access time for the entity.
|
|
1768
|
+
# <tt>'C'</tt>|Last change time for the entity.
|
|
1769
|
+
# <tt>'M'</tt>|Last modification time for the entity.
|
|
1770
|
+
# * Each of these tests operates on the modification time (`mtime`)
|
|
1771
|
+
# of each of the entities at `path0` and `path1`,
|
|
1772
|
+
# and returns a `true` or `false`;
|
|
1773
|
+
# returns `false` if either entity does not exist:
|
|
1774
|
+
# Character |Test
|
|
1775
|
+
# ------------|---------------------------------------------------------------
|
|
1776
|
+
# <tt>'<'</tt>|Whether the `mtime` at `path0` is less than that at `path1`.
|
|
1777
|
+
# <tt>'='</tt>|Whether the `mtime` at `path0` is equal to that at `path1`.
|
|
1778
|
+
# <tt>'>'</tt>|Whether the `mtime` at `path0` is greater than that at `path1`.
|
|
1779
|
+
# * This test operates on the content of each of the entities at `path0` and
|
|
1780
|
+
# `path1`,
|
|
1781
|
+
# and returns a `true` or `false`;
|
|
1782
|
+
# returns `false` if either entity does not exist:
|
|
1783
|
+
# Character |Test
|
|
1784
|
+
# ------------|---------------------------------------------
|
|
1785
|
+
# <tt>'-'</tt>|Whether the entities exist and are identical.
|
|
1672
1786
|
#
|
|
1673
1787
|
def self?.test: (String | Integer cmd, String | IO file1, ?String | IO file2) -> (TrueClass | FalseClass | Time | nil | Integer)
|
|
1674
1788
|
|
|
@@ -1719,15 +1833,19 @@ module Kernel : BasicObject
|
|
|
1719
1833
|
# baz.rb:6: warning: invalid call to foo
|
|
1720
1834
|
#
|
|
1721
1835
|
# If `category` keyword argument is given, passes the category to
|
|
1722
|
-
# `Warning.warn`. The category given must be
|
|
1723
|
-
# categories:
|
|
1836
|
+
# `Warning.warn`. The category given must be one of the following categories:
|
|
1724
1837
|
#
|
|
1725
1838
|
# :deprecated
|
|
1726
1839
|
# : Used for warning for deprecated functionality that may be removed in the
|
|
1727
1840
|
# future.
|
|
1841
|
+
#
|
|
1728
1842
|
# :experimental
|
|
1729
1843
|
# : Used for experimental features that may change in future releases.
|
|
1730
1844
|
#
|
|
1845
|
+
# :performance
|
|
1846
|
+
# : Used for warning about APIs or pattern that have negative performance
|
|
1847
|
+
# impact
|
|
1848
|
+
#
|
|
1731
1849
|
def self?.warn: (*_ToS msg, ?uplevel: int?, ?category: Warning::category?) -> nil
|
|
1732
1850
|
|
|
1733
1851
|
# <!--
|
|
@@ -1740,7 +1858,6 @@ module Kernel : BasicObject
|
|
|
1740
1858
|
# * Passing string `command_line` to the shell.
|
|
1741
1859
|
# * Invoking the executable at `exe_path`.
|
|
1742
1860
|
#
|
|
1743
|
-
#
|
|
1744
1861
|
# This method has potential security vulnerabilities if called with untrusted
|
|
1745
1862
|
# input; see [Command Injection](rdoc-ref:command_injection.rdoc).
|
|
1746
1863
|
#
|
|
@@ -1761,7 +1878,6 @@ module Kernel : BasicObject
|
|
|
1761
1878
|
# word or special built-in, or if it contains one or more meta characters.
|
|
1762
1879
|
# * `exe_path` otherwise.
|
|
1763
1880
|
#
|
|
1764
|
-
#
|
|
1765
1881
|
# **Argument `command_line`**
|
|
1766
1882
|
#
|
|
1767
1883
|
# String argument `command_line` is a command line to be passed to a shell; it
|
|
@@ -1769,7 +1885,7 @@ module Kernel : BasicObject
|
|
|
1769
1885
|
# contain meta characters:
|
|
1770
1886
|
#
|
|
1771
1887
|
# exec('if true; then echo "Foo"; fi') # Shell reserved word.
|
|
1772
|
-
# exec('
|
|
1888
|
+
# exec('exit') # Built-in.
|
|
1773
1889
|
# exec('date > date.tmp') # Contains meta character.
|
|
1774
1890
|
#
|
|
1775
1891
|
# The command line may also contain arguments and options for the command:
|
|
@@ -1793,7 +1909,6 @@ module Kernel : BasicObject
|
|
|
1793
1909
|
# * A 2-element array containing the path to an executable and the string to
|
|
1794
1910
|
# be used as the name of the executing process.
|
|
1795
1911
|
#
|
|
1796
|
-
#
|
|
1797
1912
|
# Example:
|
|
1798
1913
|
#
|
|
1799
1914
|
# exec('/usr/bin/date')
|
|
@@ -1802,7 +1917,8 @@ module Kernel : BasicObject
|
|
|
1802
1917
|
#
|
|
1803
1918
|
# Sat Aug 26 09:38:00 AM CDT 2023
|
|
1804
1919
|
#
|
|
1805
|
-
# Ruby invokes the executable directly
|
|
1920
|
+
# Ruby invokes the executable directly. This form does not use the shell; see
|
|
1921
|
+
# [Arguments args](rdoc-ref:Process@Arguments+args) for caveats.
|
|
1806
1922
|
#
|
|
1807
1923
|
# exec('doesnt_exist') # Raises Errno::ENOENT
|
|
1808
1924
|
#
|
|
@@ -1834,7 +1950,6 @@ module Kernel : BasicObject
|
|
|
1834
1950
|
# * Passing string `command_line` to the shell.
|
|
1835
1951
|
# * Invoking the executable at `exe_path`.
|
|
1836
1952
|
#
|
|
1837
|
-
#
|
|
1838
1953
|
# This method has potential security vulnerabilities if called with untrusted
|
|
1839
1954
|
# input; see [Command Injection](rdoc-ref:command_injection.rdoc).
|
|
1840
1955
|
#
|
|
@@ -1846,7 +1961,6 @@ module Kernel : BasicObject
|
|
|
1846
1961
|
# * Process.wait, to collect the termination statuses of its children.
|
|
1847
1962
|
# * Process.detach, to register disinterest in their status.
|
|
1848
1963
|
#
|
|
1849
|
-
#
|
|
1850
1964
|
# The new process is created using the [exec system
|
|
1851
1965
|
# call](https://pubs.opengroup.org/onlinepubs/9699919799.2018edition/functions/e
|
|
1852
1966
|
# xecve.html); it may inherit some of its environment from the calling program
|
|
@@ -1864,7 +1978,6 @@ module Kernel : BasicObject
|
|
|
1864
1978
|
# word or special built-in, or if it contains one or more meta characters.
|
|
1865
1979
|
# * `exe_path` otherwise.
|
|
1866
1980
|
#
|
|
1867
|
-
#
|
|
1868
1981
|
# **Argument `command_line`**
|
|
1869
1982
|
#
|
|
1870
1983
|
# String argument `command_line` is a command line to be passed to a shell; it
|
|
@@ -1873,7 +1986,7 @@ module Kernel : BasicObject
|
|
|
1873
1986
|
#
|
|
1874
1987
|
# spawn('if true; then echo "Foo"; fi') # => 798847 # Shell reserved word.
|
|
1875
1988
|
# Process.wait # => 798847
|
|
1876
|
-
# spawn('
|
|
1989
|
+
# spawn('exit') # => 798848 # Built-in.
|
|
1877
1990
|
# Process.wait # => 798848
|
|
1878
1991
|
# spawn('date > /tmp/date.tmp') # => 798879 # Contains meta character.
|
|
1879
1992
|
# Process.wait # => 798849
|
|
@@ -1898,27 +2011,19 @@ module Kernel : BasicObject
|
|
|
1898
2011
|
#
|
|
1899
2012
|
# Argument `exe_path` is one of the following:
|
|
1900
2013
|
#
|
|
1901
|
-
# * The string path to an executable to be called
|
|
2014
|
+
# * The string path to an executable to be called.
|
|
2015
|
+
# * A 2-element array containing the path to an executable to be called, and
|
|
2016
|
+
# the string to be used as the name of the executing process.
|
|
1902
2017
|
#
|
|
1903
2018
|
# spawn('/usr/bin/date') # Path to date on Unix-style system.
|
|
1904
2019
|
# Process.wait
|
|
1905
2020
|
#
|
|
1906
2021
|
# Output:
|
|
1907
2022
|
#
|
|
1908
|
-
#
|
|
1909
|
-
#
|
|
1910
|
-
# * A 2-element array containing the path to an executable and the string to
|
|
1911
|
-
# be used as the name of the executing process:
|
|
1912
|
-
#
|
|
1913
|
-
# pid = spawn(['sleep', 'Hello!'], '1') # 2-element array.
|
|
1914
|
-
# p `ps -p #{pid} -o command=`
|
|
1915
|
-
#
|
|
1916
|
-
# Output:
|
|
1917
|
-
#
|
|
1918
|
-
# "Hello! 1\n"
|
|
2023
|
+
# Mon Aug 28 11:43:10 AM CDT 2023
|
|
1919
2024
|
#
|
|
1920
|
-
#
|
|
1921
|
-
#
|
|
2025
|
+
# Ruby invokes the executable directly. This form does not use the shell; see
|
|
2026
|
+
# [Arguments args](rdoc-ref:Process@Arguments+args) for caveats.
|
|
1922
2027
|
#
|
|
1923
2028
|
# If one or more `args` is given, each is an argument or option to be passed to
|
|
1924
2029
|
# the executable:
|
|
@@ -1948,7 +2053,6 @@ module Kernel : BasicObject
|
|
|
1948
2053
|
# * Passing string `command_line` to the shell.
|
|
1949
2054
|
# * Invoking the executable at `exe_path`.
|
|
1950
2055
|
#
|
|
1951
|
-
#
|
|
1952
2056
|
# This method has potential security vulnerabilities if called with untrusted
|
|
1953
2057
|
# input; see [Command Injection](rdoc-ref:command_injection.rdoc).
|
|
1954
2058
|
#
|
|
@@ -1958,7 +2062,6 @@ module Kernel : BasicObject
|
|
|
1958
2062
|
# * `false` if the exit status is a non-zero integer.
|
|
1959
2063
|
# * `nil` if the command could not execute.
|
|
1960
2064
|
#
|
|
1961
|
-
#
|
|
1962
2065
|
# Raises an exception (instead of returning `false` or `nil`) if keyword
|
|
1963
2066
|
# argument `exception` is set to `true`.
|
|
1964
2067
|
#
|
|
@@ -1981,7 +2084,6 @@ module Kernel : BasicObject
|
|
|
1981
2084
|
# word or special built-in, or if it contains one or more meta characters.
|
|
1982
2085
|
# * `exe_path` otherwise.
|
|
1983
2086
|
#
|
|
1984
|
-
#
|
|
1985
2087
|
# **Argument `command_line`**
|
|
1986
2088
|
#
|
|
1987
2089
|
# String argument `command_line` is a command line to be passed to a shell; it
|
|
@@ -1989,14 +2091,14 @@ module Kernel : BasicObject
|
|
|
1989
2091
|
# contain meta characters:
|
|
1990
2092
|
#
|
|
1991
2093
|
# system('if true; then echo "Foo"; fi') # => true # Shell reserved word.
|
|
1992
|
-
# system('
|
|
2094
|
+
# system('exit') # => true # Built-in.
|
|
1993
2095
|
# system('date > /tmp/date.tmp') # => true # Contains meta character.
|
|
1994
2096
|
# system('date > /nop/date.tmp') # => false
|
|
1995
2097
|
# system('date > /nop/date.tmp', exception: true) # Raises RuntimeError.
|
|
1996
2098
|
#
|
|
1997
2099
|
# Assigns the command's error status to `$?`:
|
|
1998
2100
|
#
|
|
1999
|
-
# system('
|
|
2101
|
+
# system('exit') # => true # Built-in.
|
|
2000
2102
|
# $? # => #<Process::Status: pid 640610 exit 0>
|
|
2001
2103
|
# system('date > /nop/date.tmp') # => false
|
|
2002
2104
|
# $? # => #<Process::Status: pid 640742 exit 2>
|
|
@@ -2022,7 +2124,6 @@ module Kernel : BasicObject
|
|
|
2022
2124
|
# * A 2-element array containing the path to an executable and the string to
|
|
2023
2125
|
# be used as the name of the executing process.
|
|
2024
2126
|
#
|
|
2025
|
-
#
|
|
2026
2127
|
# Example:
|
|
2027
2128
|
#
|
|
2028
2129
|
# system('/usr/bin/date') # => true # Path to date on Unix-style system.
|
|
@@ -2039,7 +2140,8 @@ module Kernel : BasicObject
|
|
|
2039
2140
|
# system('foo') # => nil
|
|
2040
2141
|
# $? # => #<Process::Status: pid 645608 exit 127>
|
|
2041
2142
|
#
|
|
2042
|
-
# Ruby invokes the executable directly
|
|
2143
|
+
# Ruby invokes the executable directly. This form does not use the shell; see
|
|
2144
|
+
# [Arguments args](rdoc-ref:Process@Arguments+args) for caveats.
|
|
2043
2145
|
#
|
|
2044
2146
|
# system('doesnt_exist') # => nil
|
|
2045
2147
|
#
|
|
@@ -2117,7 +2219,7 @@ module Kernel : BasicObject
|
|
|
2117
2219
|
# s1.inspect #=> "#<Klass:0x401b3a38 @str=\"Hi\">"
|
|
2118
2220
|
# s2.inspect #=> "#<Klass:0x401b3998 @str=\"Hi\">"
|
|
2119
2221
|
#
|
|
2120
|
-
# This method may have class-specific behavior.
|
|
2222
|
+
# This method may have class-specific behavior. If so, that behavior will be
|
|
2121
2223
|
# documented under the #`initialize_copy` method of the class.
|
|
2122
2224
|
#
|
|
2123
2225
|
def clone: (?freeze: bool?) -> self
|
|
@@ -2885,7 +2987,7 @@ module Kernel : BasicObject
|
|
|
2885
2987
|
# rdoc-file=kernel.rb
|
|
2886
2988
|
# - obj.tap {|x| block } -> obj
|
|
2887
2989
|
# -->
|
|
2888
|
-
# Yields self to the block
|
|
2990
|
+
# Yields self to the block and then returns self. The primary purpose of this
|
|
2889
2991
|
# method is to "tap into" a method chain, in order to perform operations on
|
|
2890
2992
|
# intermediate results within the chain.
|
|
2891
2993
|
#
|
|
@@ -2909,11 +3011,8 @@ module Kernel : BasicObject
|
|
|
2909
3011
|
|
|
2910
3012
|
# <!--
|
|
2911
3013
|
# rdoc-file=kernel.rb
|
|
2912
|
-
# -
|
|
3014
|
+
# - yield_self()
|
|
2913
3015
|
# -->
|
|
2914
|
-
# Yields self to the block and returns the result of the block.
|
|
2915
|
-
#
|
|
2916
|
-
# "my string".yield_self {|s| s.upcase } #=> "MY STRING"
|
|
2917
3016
|
#
|
|
2918
3017
|
def yield_self: () -> Enumerator[self, untyped]
|
|
2919
3018
|
| [T] () { (self) -> T } -> T
|
|
@@ -2926,32 +3025,23 @@ module Kernel : BasicObject
|
|
|
2926
3025
|
#
|
|
2927
3026
|
# 3.next.then {|x| x**x }.to_s #=> "256"
|
|
2928
3027
|
#
|
|
2929
|
-
#
|
|
3028
|
+
# A good use of `then` is value piping in method chains:
|
|
2930
3029
|
#
|
|
2931
3030
|
# require 'open-uri'
|
|
2932
3031
|
# require 'json'
|
|
2933
3032
|
#
|
|
2934
|
-
# construct_url(arguments)
|
|
2935
|
-
# then {|url| URI(url).read }
|
|
2936
|
-
# then {|response| JSON.parse(response) }
|
|
3033
|
+
# construct_url(arguments)
|
|
3034
|
+
# .then {|url| URI(url).read }
|
|
3035
|
+
# .then {|response| JSON.parse(response) }
|
|
2937
3036
|
#
|
|
2938
|
-
# When called without block, the method returns `Enumerator`, which can be
|
|
2939
|
-
# for example, for conditional circuit-breaking:
|
|
3037
|
+
# When called without a block, the method returns an `Enumerator`, which can be
|
|
3038
|
+
# used, for example, for conditional circuit-breaking:
|
|
2940
3039
|
#
|
|
2941
|
-
# #
|
|
3040
|
+
# # Meets condition, no-op
|
|
2942
3041
|
# 1.then.detect(&:odd?) # => 1
|
|
2943
|
-
# #
|
|
3042
|
+
# # Does not meet condition, drop value
|
|
2944
3043
|
# 2.then.detect(&:odd?) # => nil
|
|
2945
3044
|
#
|
|
2946
|
-
# Good usage for `then` is value piping in method chains:
|
|
2947
|
-
#
|
|
2948
|
-
# require 'open-uri'
|
|
2949
|
-
# require 'json'
|
|
2950
|
-
#
|
|
2951
|
-
# construct_url(arguments).
|
|
2952
|
-
# then {|url| URI(url).read }.
|
|
2953
|
-
# then {|response| JSON.parse(response) }
|
|
2954
|
-
#
|
|
2955
3045
|
alias then yield_self
|
|
2956
3046
|
|
|
2957
3047
|
private
|