rbs 3.0.0.dev.2 → 3.0.0.dev.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (112) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/comments.yml +2 -1
  3. data/.github/workflows/ruby.yml +4 -0
  4. data/Gemfile.lock +11 -11
  5. data/Rakefile +2 -2
  6. data/Steepfile +1 -1
  7. data/core/array.rbs +573 -423
  8. data/core/basic_object.rbs +11 -39
  9. data/core/binding.rbs +1 -1
  10. data/core/builtin.rbs +8 -0
  11. data/core/class.rbs +37 -0
  12. data/core/comparable.rbs +7 -18
  13. data/core/complex.rbs +2 -2
  14. data/core/data.rbs +419 -0
  15. data/core/dir.rbs +52 -104
  16. data/core/encoding.rbs +22 -181
  17. data/core/enumerable.rbs +212 -175
  18. data/core/enumerator/product.rbs +96 -0
  19. data/core/enumerator.rbs +57 -8
  20. data/core/errors.rbs +8 -2
  21. data/core/exception.rbs +41 -0
  22. data/core/fiber.rbs +95 -12
  23. data/core/file.rbs +840 -275
  24. data/core/file_test.rbs +34 -19
  25. data/core/float.rbs +40 -96
  26. data/core/gc.rbs +15 -3
  27. data/core/hash.rbs +113 -175
  28. data/core/integer.rbs +85 -145
  29. data/core/io/buffer.rbs +187 -60
  30. data/core/io/wait.rbs +28 -16
  31. data/core/io.rbs +1859 -1389
  32. data/core/kernel.rbs +525 -961
  33. data/core/match_data.rbs +306 -142
  34. data/core/math.rbs +506 -234
  35. data/core/method.rbs +0 -24
  36. data/core/module.rbs +110 -17
  37. data/core/nil_class.rbs +2 -0
  38. data/core/numeric.rbs +76 -144
  39. data/core/object.rbs +88 -212
  40. data/core/proc.rbs +17 -5
  41. data/core/process.rbs +22 -5
  42. data/core/ractor.rbs +1 -1
  43. data/core/random.rbs +20 -3
  44. data/core/range.rbs +91 -89
  45. data/core/rational.rbs +2 -3
  46. data/core/rbs/unnamed/argf.rbs +177 -120
  47. data/core/rbs/unnamed/env_class.rbs +89 -163
  48. data/core/rbs/unnamed/random.rbs +36 -12
  49. data/core/refinement.rbs +8 -0
  50. data/core/regexp.rbs +462 -272
  51. data/core/ruby_vm.rbs +210 -0
  52. data/{stdlib/set/0 → core}/set.rbs +43 -47
  53. data/core/string.rbs +1403 -1332
  54. data/core/string_io.rbs +191 -107
  55. data/core/struct.rbs +67 -63
  56. data/core/symbol.rbs +187 -201
  57. data/core/thread.rbs +40 -35
  58. data/core/time.rbs +902 -826
  59. data/core/trace_point.rbs +55 -6
  60. data/core/unbound_method.rbs +48 -24
  61. data/docs/collection.md +4 -0
  62. data/docs/syntax.md +55 -0
  63. data/ext/rbs_extension/parser.c +5 -6
  64. data/lib/rbs/cli.rb +6 -1
  65. data/lib/rbs/collection/cleaner.rb +8 -1
  66. data/lib/rbs/collection/config/lockfile.rb +3 -1
  67. data/lib/rbs/collection/config/lockfile_generator.rb +16 -14
  68. data/lib/rbs/collection/config.rb +1 -1
  69. data/lib/rbs/collection/sources/git.rb +9 -2
  70. data/lib/rbs/collection/sources/local.rb +79 -0
  71. data/lib/rbs/collection/sources.rb +8 -1
  72. data/lib/rbs/environment.rb +6 -5
  73. data/lib/rbs/environment_loader.rb +3 -2
  74. data/lib/rbs/errors.rb +18 -0
  75. data/lib/rbs/locator.rb +26 -7
  76. data/lib/rbs/sorter.rb +2 -2
  77. data/lib/rbs/version.rb +1 -1
  78. data/sig/collection/sources.rbs +32 -3
  79. data/sig/environment.rbs +2 -3
  80. data/sig/locator.rbs +14 -2
  81. data/sig/shims/{abstract_syntax_tree.rbs → _abstract_syntax_tree.rbs} +0 -0
  82. data/stdlib/bigdecimal/0/big_decimal.rbs +16 -13
  83. data/stdlib/cgi/0/core.rbs +16 -0
  84. data/stdlib/coverage/0/coverage.rbs +50 -8
  85. data/stdlib/csv/0/csv.rbs +1 -1
  86. data/stdlib/date/0/date.rbs +856 -726
  87. data/stdlib/date/0/date_time.rbs +83 -210
  88. data/stdlib/erb/0/erb.rbs +13 -36
  89. data/stdlib/etc/0/etc.rbs +127 -20
  90. data/stdlib/fileutils/0/fileutils.rbs +1290 -381
  91. data/stdlib/logger/0/logger.rbs +466 -316
  92. data/stdlib/net-http/0/net-http.rbs +2211 -534
  93. data/stdlib/nkf/0/nkf.rbs +5 -5
  94. data/stdlib/objspace/0/objspace.rbs +31 -14
  95. data/stdlib/openssl/0/openssl.rbs +11 -7
  96. data/stdlib/optparse/0/optparse.rbs +20 -17
  97. data/stdlib/pathname/0/pathname.rbs +21 -4
  98. data/stdlib/pstore/0/pstore.rbs +378 -154
  99. data/stdlib/pty/0/pty.rbs +24 -8
  100. data/stdlib/ripper/0/ripper.rbs +1650 -0
  101. data/stdlib/socket/0/addrinfo.rbs +9 -15
  102. data/stdlib/socket/0/socket.rbs +36 -3
  103. data/stdlib/strscan/0/string_scanner.rbs +7 -5
  104. data/stdlib/tempfile/0/tempfile.rbs +104 -44
  105. data/stdlib/time/0/time.rbs +2 -2
  106. data/stdlib/uri/0/file.rbs +5 -0
  107. data/stdlib/uri/0/generic.rbs +2 -2
  108. data/stdlib/yaml/0/yaml.rbs +2 -2
  109. data/stdlib/zlib/0/zlib.rbs +1 -1
  110. metadata +8 -6
  111. data/core/deprecated.rbs +0 -9
  112. data/sig/shims/ripper.rbs +0 -8
data/core/regexp.rbs CHANGED
@@ -1,13 +1,4 @@
1
1
  # <!-- rdoc-file=re.c -->
2
- # A Regexp holds a regular expression, used to match a pattern against strings.
3
- # Regexps are created using the `/.../` and `%r{...}` literals, and by the
4
- # Regexp::new constructor.
5
- #
6
- # You can create a Regexp object explicitly with:
7
- #
8
- # * A [regexp literal](doc/syntax/literals_rdoc.html#label-Regexp+Literals).
9
- #
10
- #
11
2
  # Regular expressions (*regexp*s) are patterns which describe the contents of a
12
3
  # string. They're used for testing whether a string contains a given pattern, or
13
4
  # extracting the portions that match. They are created with the `/`*pat*`/` and
@@ -32,12 +23,22 @@
32
23
  # Specifically, `/st/` requires that the string contains the letter *s* followed
33
24
  # by the letter *t*, so it matches *haystack*, also.
34
25
  #
26
+ # Note that any Regexp matching will raise a RuntimeError if timeout is set and
27
+ # exceeded. See ["Timeout"](#label-Timeout) section in detail.
28
+ #
29
+ # ## Regexp Interpolation
30
+ #
31
+ # A regexp may contain interpolated strings; trivially:
32
+ #
33
+ # foo = 'bar'
34
+ # /#{foo}/ # => /bar/
35
+ #
35
36
  # ## `=~` and Regexp#match
36
37
  #
37
38
  # Pattern matching may be achieved by using `=~` operator or Regexp#match
38
39
  # method.
39
40
  #
40
- # ### `=~` operator
41
+ # ### `=~` Operator
41
42
  #
42
43
  # `=~` is Ruby's basic pattern-matching operator. When one operand is a regular
43
44
  # expression and the other is a string then the regular expression is used as a
@@ -55,7 +56,7 @@
55
56
  # after a successful match. `$~` holds a MatchData object. Regexp.last_match is
56
57
  # equivalent to `$~`.
57
58
  #
58
- # ### Regexp#match method
59
+ # ### Regexp#match Method
59
60
  #
60
61
  # The #match method returns a MatchData object:
61
62
  #
@@ -190,7 +191,7 @@
190
191
  #
191
192
  # "Hello".match(/[[:upper:]]+[[:lower:]]+l{2}o/) #=> #<MatchData "Hello">
192
193
  #
193
- # ### Greedy match
194
+ # ### Greedy Match
194
195
  #
195
196
  # Repetition is *greedy* by default: as many occurrences as possible are matched
196
197
  # while still allowing the overall match to succeed. By contrast, *lazy*
@@ -207,7 +208,7 @@
207
208
  # /<.+>/.match("<a><b>") #=> #<MatchData "<a><b>">
208
209
  # /<.+?>/.match("<a><b>") #=> #<MatchData "<a>">
209
210
  #
210
- # ### Possessive match
211
+ # ### Possessive Match
211
212
  #
212
213
  # A quantifier followed by `+` matches *possessively*: once it has matched it
213
214
  # does not backtrack. They behave like greedy quantifiers, but having matched
@@ -249,7 +250,7 @@
249
250
  # "The cat sat in the hat".gsub(/[csh]at/, '\0s')
250
251
  # # => "The cats sats in the hats"
251
252
  #
252
- # ### Named captures
253
+ # ### Named Captures
253
254
  #
254
255
  # Capture groups can be referred to by name when defined with the
255
256
  # `(?<`*name*`>)` or `(?'`*name*`')` constructs.
@@ -395,6 +396,7 @@
395
396
  # * `/\p{Blank}/` - Space or tab
396
397
  # * `/\p{Cntrl}/` - Control character
397
398
  # * `/\p{Digit}/` - Digit
399
+ # * `/\p{Emoji}/` - Unicode emoji
398
400
  # * `/\p{Graph}/` - Non-blank character (excludes spaces, control characters,
399
401
  # and similar)
400
402
  # * `/\p{Lower}/` - Lowercase alphabetical character
@@ -523,11 +525,16 @@
523
525
  # * `(?<!`*pat*`)` - *Negative lookbehind* assertion: ensures that the
524
526
  # preceding characters do not match *pat*, but doesn't include those
525
527
  # characters in the matched text
526
- # * `\K` - Uses an positive lookbehind of the content preceding `\K` in the
527
- # regexp. For example, the following two regexps are almost equivalent:
528
528
  #
529
- # /ab\Kc/
530
- # /(?<=ab)c/
529
+ # * `\K` - *Match reset*: the matched content preceding `\K` in the regexp is
530
+ # excluded from the result. For example, the following two regexps are
531
+ # almost equivalent:
532
+ #
533
+ # /ab\Kc/ =~ "abc" #=> 0
534
+ # /(?<=ab)c/ =~ "abc" #=> 2
535
+ #
536
+ # These match same string and *$&* equals `"c"`, while the matched position
537
+ # is different.
531
538
  #
532
539
  # As are the following two regexps:
533
540
  #
@@ -592,6 +599,11 @@
592
599
  # Regexp.new("abc # Comment", Regexp::EXTENDED) #=> /abc # Comment/x
593
600
  # Regexp.new("abc", Regexp::IGNORECASE | Regexp::MULTILINE) #=> /abc/mi
594
601
  #
602
+ # Regexp.new("abc", "i") #=> /abc/i
603
+ # Regexp.new("abc", "m") #=> /abc/m
604
+ # Regexp.new("abc # Comment", "x") #=> /abc # Comment/x
605
+ # Regexp.new("abc", "im") #=> /abc/mi
606
+ #
595
607
  # ## Free-Spacing Mode and Comments
596
608
  #
597
609
  # As mentioned above, the `x` option enables *free-spacing* mode. Literal white
@@ -649,9 +661,10 @@
649
661
  # # raises Encoding::CompatibilityError: incompatible encoding regexp match
650
662
  # # (ISO-8859-1 regexp with UTF-8 string)
651
663
  #
652
- # ## Special global variables
664
+ # ## Regexp Global Variables
653
665
  #
654
666
  # Pattern matching sets some global variables :
667
+ #
655
668
  # * `$~` is equivalent to Regexp.last_match;
656
669
  # * `$&` contains the complete matched text;
657
670
  # * `$`` contains string before match;
@@ -738,30 +751,79 @@
738
751
  #
739
752
  # Regexp.new('a{0,29}' + 'a' * 29) =~ 'a' * 29
740
753
  #
754
+ # ## Timeout
755
+ #
756
+ # There are two APIs to set timeout. One is Regexp.timeout=, which is
757
+ # process-global configuration of timeout for Regexp matching.
758
+ #
759
+ # Regexp.timeout = 3
760
+ # s = 'a' * 25 + 'd' + 'a' * 4 + 'c'
761
+ # /(b|a+)*c/ =~ s #=> This raises an exception in three seconds
762
+ #
763
+ # The other is timeout keyword of Regexp.new.
764
+ #
765
+ # re = Regexp.new("(b|a+)*c", timeout: 3)
766
+ # s = 'a' * 25 + 'd' + 'a' * 4 + 'c'
767
+ # /(b|a+)*c/ =~ s #=> This raises an exception in three seconds
768
+ #
769
+ # When using Regexps to process untrusted input, you should use the timeout
770
+ # feature to avoid excessive backtracking. Otherwise, a malicious user can
771
+ # provide input to Regexp causing Denial-of-Service attack. Note that the
772
+ # timeout is not set by default because an appropriate limit highly depends on
773
+ # an application requirement and context.
774
+ #
741
775
  class Regexp
742
776
  # <!--
743
777
  # rdoc-file=re.c
744
- # - Regexp.new(string, [options]) -> regexp
745
- # - Regexp.new(regexp) -> regexp
746
- # - Regexp.compile(string, [options]) -> regexp
747
- # - Regexp.compile(regexp) -> regexp
778
+ # - Regexp.new(string, options = 0, timeout: nil) -> regexp
779
+ # - Regexp.new(regexp, timeout: nil) -> regexp
748
780
  # -->
749
- # Constructs a new regular expression from `pattern`, which can be either a
750
- # String or a Regexp (in which case that regexp's options are propagated), and
751
- # new options may not be specified (a change as of Ruby 1.8).
752
- #
753
- # If `options` is an Integer, it should be one or more of the constants
754
- # Regexp::EXTENDED, Regexp::IGNORECASE, and Regexp::MULTILINE, *or*-ed together.
755
- # Otherwise, if `options` is not `nil` or `false`, the regexp will be case
756
- # insensitive.
757
- #
758
- # r1 = Regexp.new('^a-z+:\\s+\w+') #=> /^a-z+:\s+\w+/
759
- # r2 = Regexp.new('cat', true) #=> /cat/i
760
- # r3 = Regexp.new(r2) #=> /cat/i
761
- # r4 = Regexp.new('dog', Regexp::EXTENDED | Regexp::IGNORECASE) #=> /dog/ix
762
- #
763
- def initialize: (String string, ?Integer | nil | false | top options, ?String kcode) -> Object
764
- | (Regexp regexp) -> void
781
+ # With argument `string` given, returns a new regexp with the given string and
782
+ # options:
783
+ #
784
+ # r = Regexp.new('foo') # => /foo/
785
+ # r.source # => "foo"
786
+ # r.options # => 0
787
+ #
788
+ # Optional argument `options` is one of the following:
789
+ #
790
+ # * A String of options:
791
+ #
792
+ # Regexp.new('foo', 'i') # => /foo/i
793
+ # Regexp.new('foo', 'im') # => /foo/im
794
+ #
795
+ # * The logical OR of one or more of the constants Regexp::EXTENDED,
796
+ # Regexp::IGNORECASE, Regexp::MULTILINE, and Regexp::NOENCODING:
797
+ #
798
+ # Regexp.new('foo', Regexp::IGNORECASE) # => /foo/i
799
+ # Regexp.new('foo', Regexp::EXTENDED) # => /foo/x
800
+ # Regexp.new('foo', Regexp::MULTILINE) # => /foo/m
801
+ # Regexp.new('foo', Regexp::NOENCODING) # => /foo/n
802
+ # flags = Regexp::IGNORECASE | Regexp::EXTENDED | Regexp::MULTILINE
803
+ # Regexp.new('foo', flags) # => /foo/mix
804
+ #
805
+ # * `nil` or `false`, which is ignored.
806
+ #
807
+ #
808
+ # If optional keyword argument `timeout` is given, its float value overrides the
809
+ # timeout interval for the class, Regexp.timeout. If `nil` is passed as
810
+ # +timeout, it uses the timeout interval for the class, Regexp.timeout.
811
+ #
812
+ # With argument `regexp` given, returns a new regexp. The source, options,
813
+ # timeout are the same as `regexp`. `options` and `n_flag` arguments are
814
+ # ineffective. The timeout can be overridden by `timeout` keyword.
815
+ #
816
+ # options = Regexp::MULTILINE
817
+ # r = Regexp.new('foo', options, timeout: 1.1) # => /foo/m
818
+ # r2 = Regexp.new(r) # => /foo/m
819
+ # r2.timeout # => 1.1
820
+ # r3 = Regexp.new(r, timeout: 3.14) # => /foo/m
821
+ # r3.timeout # => 3.14
822
+ #
823
+ # Regexp.compile is an alias for Regexp.new.
824
+ #
825
+ def initialize: (String string, ?String | Integer | nil | false options, ?timeout: Float?) -> Object
826
+ | (Regexp regexp, ?timeout: Float?) -> void
765
827
 
766
828
  # <!--
767
829
  # rdoc-file=re.c
@@ -773,42 +835,57 @@ class Regexp
773
835
 
774
836
  # <!--
775
837
  # rdoc-file=re.c
776
- # - Regexp.escape(str) -> string
777
- # - Regexp.quote(str) -> string
838
+ # - Regexp.escape(string) -> new_string
778
839
  # -->
779
- # Escapes any characters that would have special meaning in a regular
780
- # expression. Returns a new escaped string with the same or compatible encoding.
781
- # For any string, `Regexp.new(Regexp.escape(*str*))=~*str`* will be true.
840
+ # Returns a new string that escapes any characters that have special meaning in
841
+ # a regular expression:
842
+ #
843
+ # s = Regexp.escape('\*?{}.') # => "\\\\\\*\\?\\{\\}\\."
782
844
  #
783
- # Regexp.escape('\*?{}.') #=> \\\*\?\{\}\.
845
+ # For any string `s`, this call returns a MatchData object:
846
+ #
847
+ # r = Regexp.new(Regexp.escape(s)) # => /\\\\\\\*\\\?\\\{\\\}\\\./
848
+ # r.match(s) # => #<MatchData "\\\\\\*\\?\\{\\}\\.">
849
+ #
850
+ # Regexp.quote is an alias for Regexp.escape.
784
851
  #
785
852
  def self.escape: (String | Symbol str) -> String
786
853
 
787
854
  # <!--
788
855
  # rdoc-file=re.c
789
- # - Regexp.last_match -> matchdata
790
- # - Regexp.last_match(n) -> str
856
+ # - Regexp.last_match -> matchdata or nil
857
+ # - Regexp.last_match(n) -> string or nil
858
+ # - Regexp.last_match(name) -> string or nil
791
859
  # -->
792
- # The first form returns the MatchData object generated by the last successful
793
- # pattern match. Equivalent to reading the special global variable `$~` (see
794
- # Special global variables in Regexp for details).
860
+ # With no argument, returns the value of `$!`, which is the result of the most
861
+ # recent pattern match (see [Regexp Global
862
+ # Variables](rdoc-ref:Regexp@Regexp+Global+Variables)):
863
+ #
864
+ # /c(.)t/ =~ 'cat' # => 0
865
+ # Regexp.last_match # => #<MatchData "cat" 1:"a">
866
+ # /a/ =~ 'foo' # => nil
867
+ # Regexp.last_match # => nil
868
+ #
869
+ # With non-negative integer argument `n`, returns the _n_th field in the
870
+ # matchdata, if any, or nil if none:
795
871
  #
796
- # The second form returns the *n*th field in this MatchData object. *n* can be a
797
- # string or symbol to reference a named capture.
872
+ # /c(.)t/ =~ 'cat' # => 0
873
+ # Regexp.last_match(0) # => "cat"
874
+ # Regexp.last_match(1) # => "a"
875
+ # Regexp.last_match(2) # => nil
798
876
  #
799
- # Note that the last_match is local to the thread and method scope of the method
800
- # that did the pattern match.
877
+ # With negative integer argument `n`, counts backwards from the last field:
801
878
  #
802
- # /c(.)t/ =~ 'cat' #=> 0
803
- # Regexp.last_match #=> #<MatchData "cat" 1:"a">
804
- # Regexp.last_match(0) #=> "cat"
805
- # Regexp.last_match(1) #=> "a"
806
- # Regexp.last_match(2) #=> nil
879
+ # Regexp.last_match(-1) # => "a"
807
880
  #
808
- # /(?<lhs>\w+)\s*=\s*(?<rhs>\w+)/ =~ "var = val"
809
- # Regexp.last_match #=> #<MatchData "var = val" lhs:"var" rhs:"val">
810
- # Regexp.last_match(:lhs) #=> "var"
811
- # Regexp.last_match(:rhs) #=> "val"
881
+ # With string or symbol argument `name`, returns the string value for the named
882
+ # capture, if any:
883
+ #
884
+ # /(?<lhs>\w+)\s*=\s*(?<rhs>\w+)/ =~ 'var = val'
885
+ # Regexp.last_match # => #<MatchData "var = val" lhs:"var"rhs:"val">
886
+ # Regexp.last_match(:lhs) # => "var"
887
+ # Regexp.last_match('rhs') # => "val"
888
+ # Regexp.last_match('foo') # Raises IndexError.
812
889
  #
813
890
  def self.last_match: () -> MatchData?
814
891
  | (Integer n) -> String?
@@ -816,54 +893,116 @@ class Regexp
816
893
 
817
894
  # <!--
818
895
  # rdoc-file=re.c
819
- # - Regexp.escape(str) -> string
820
- # - Regexp.quote(str) -> string
896
+ # - Regexp.linear_time?(re)
897
+ # - Regexp.linear_time?(string, options = 0)
821
898
  # -->
822
- # Escapes any characters that would have special meaning in a regular
823
- # expression. Returns a new escaped string with the same or compatible encoding.
824
- # For any string, `Regexp.new(Regexp.escape(*str*))=~*str`* will be true.
899
+ # Returns `true` if matching against `re` can be done in linear time to the
900
+ # input string.
901
+ #
902
+ # Regexp.linear_time?(/re/) # => true
903
+ #
904
+ # Note that this is a property of the ruby interpreter, not of the argument
905
+ # regular expression. Identical regexp can or cannot run in linear time
906
+ # depending on your ruby binary. Neither forward nor backward compatibility is
907
+ # guaranteed about the return value of this method. Our current algorithm is
908
+ # (*1) but this is subject to change in the future. Alternative implementations
909
+ # can also behave differently. They might always return false for everything.
825
910
  #
826
- # Regexp.escape('\*?{}.') #=> \\\*\?\{\}\.
911
+ # (*1): https://doi.org/10.1109/SP40001.2021.00032
912
+ #
913
+ def self.linear_time?: () -> bool
914
+
915
+ # <!--
916
+ # rdoc-file=re.c
917
+ # - Regexp.escape(string) -> new_string
918
+ # -->
919
+ # Returns a new string that escapes any characters that have special meaning in
920
+ # a regular expression:
921
+ #
922
+ # s = Regexp.escape('\*?{}.') # => "\\\\\\*\\?\\{\\}\\."
923
+ #
924
+ # For any string `s`, this call returns a MatchData object:
925
+ #
926
+ # r = Regexp.new(Regexp.escape(s)) # => /\\\\\\\*\\\?\\\{\\\}\\\./
927
+ # r.match(s) # => #<MatchData "\\\\\\*\\?\\{\\}\\.">
928
+ #
929
+ # Regexp.quote is an alias for Regexp.escape.
827
930
  #
828
931
  def self.quote: (String | Symbol str) -> String
829
932
 
830
933
  # <!--
831
934
  # rdoc-file=re.c
832
- # - Regexp.try_convert(obj) -> re or nil
935
+ # - Regexp.try_convert(object) -> regexp or nil
833
936
  # -->
834
- # Try to convert *obj* into a Regexp, using to_regexp method. Returns converted
835
- # regexp or nil if *obj* cannot be converted for any reason.
937
+ # Returns `object` if it is a regexp:
938
+ #
939
+ # Regexp.try_convert(/re/) # => /re/
836
940
  #
837
- # Regexp.try_convert(/re/) #=> /re/
838
- # Regexp.try_convert("re") #=> nil
941
+ # Otherwise if `object` responds to `:to_regexp`, calls `object.to_regexp` and
942
+ # returns the result.
839
943
  #
840
- # o = Object.new
841
- # Regexp.try_convert(o) #=> nil
842
- # def o.to_regexp() /foo/ end
843
- # Regexp.try_convert(o) #=> /foo/
944
+ # Returns `nil` if `object` does not respond to `:to_regexp`.
945
+ #
946
+ # Regexp.try_convert('re') # => nil
947
+ #
948
+ # Raises an exception unless `object.to_regexp` returns a regexp.
844
949
  #
845
950
  def self.try_convert: (untyped obj) -> Regexp?
846
951
 
847
952
  # <!--
848
953
  # rdoc-file=re.c
849
- # - Regexp.union(pat1, pat2, ...) -> new_regexp
850
- # - Regexp.union(pats_ary) -> new_regexp
954
+ # - Regexp.timeout -> float or nil
955
+ # -->
956
+ # It returns the current default timeout interval for Regexp matching in second.
957
+ # `nil` means no default timeout configuration.
958
+ #
959
+ def self.timeout: () -> Float?
960
+
961
+ # <!--
962
+ # rdoc-file=re.c
963
+ # - Regexp.timeout = float or nil
964
+ # -->
965
+ # It sets the default timeout interval for Regexp matching in second. `nil`
966
+ # means no default timeout configuration. This configuration is process-global.
967
+ # If you want to set timeout for each Regexp, use `timeout` keyword for
968
+ # `Regexp.new`.
969
+ #
970
+ # Regexp.timeout = 1
971
+ # /^a*b?a*$/ =~ "a" * 100000 + "x" #=> regexp match timeout (RuntimeError)
972
+ #
973
+ def self.timeout=: (Float?) -> Float?
974
+
975
+ # <!--
976
+ # rdoc-file=re.c
977
+ # - Regexp.union(*patterns) -> regexp
978
+ # - Regexp.union(array_of_patterns) -> regexp
851
979
  # -->
852
- # Return a Regexp object that is the union of the given *pattern*s, i.e., will
853
- # match any of its parts. The *pattern*s can be Regexp objects, in which case
854
- # their options will be preserved, or Strings. If no patterns are given, returns
855
- # `/(?!)/`. The behavior is unspecified if any given *pattern* contains
856
- # capture.
857
- #
858
- # Regexp.union #=> /(?!)/
859
- # Regexp.union("penzance") #=> /penzance/
860
- # Regexp.union("a+b*c") #=> /a\+b\*c/
861
- # Regexp.union("skiing", "sledding") #=> /skiing|sledding/
862
- # Regexp.union(["skiing", "sledding"]) #=> /skiing|sledding/
863
- # Regexp.union(/dogs/, /cats/i) #=> /(?-mix:dogs)|(?i-mx:cats)/
864
- #
865
- # Note: the arguments for ::union will try to be converted into a regular
866
- # expression literal via #to_regexp.
980
+ # Returns a new regexp that is the union of the given patterns:
981
+ #
982
+ # r = Regexp.union(%w[cat dog]) # => /cat|dog/
983
+ # r.match('cat') # => #<MatchData "cat">
984
+ # r.match('dog') # => #<MatchData "dog">
985
+ # r.match('cog') # => nil
986
+ #
987
+ # For each pattern that is a string, `Regexp.new(pattern)` is used:
988
+ #
989
+ # Regexp.union('penzance') # => /penzance/
990
+ # Regexp.union('a+b*c') # => /a\+b\*c/
991
+ # Regexp.union('skiing', 'sledding') # => /skiing|sledding/
992
+ # Regexp.union(['skiing', 'sledding']) # => /skiing|sledding/
993
+ #
994
+ # For each pattern that is a regexp, it is used as is, including its flags:
995
+ #
996
+ # Regexp.union(/foo/i, /bar/m, /baz/x)
997
+ # # => /(?i-mx:foo)|(?m-ix:bar)|(?x-mi:baz)/
998
+ # Regexp.union([/foo/i, /bar/m, /baz/x])
999
+ # # => /(?i-mx:foo)|(?m-ix:bar)|(?x-mi:baz)/
1000
+ #
1001
+ # With no arguments, returns `/(?!)/`:
1002
+ #
1003
+ # Regexp.union # => /(?!)/
1004
+ #
1005
+ # If any regexp pattern contains captures, the behavior is unspecified.
867
1006
  #
868
1007
  def self.union: () -> Regexp
869
1008
  | (String | Regexp pat1, *String | Regexp pat2) -> Regexp
@@ -872,93 +1011,103 @@ class Regexp
872
1011
  public
873
1012
 
874
1013
  # <!-- rdoc-file=re.c -->
875
- # Equality---Two regexps are equal if their patterns are identical, they have
876
- # the same character set code, and their `casefold?` values are the same.
1014
+ # Returns `true` if `object` is another Regexp whose pattern, flags, and
1015
+ # encoding are the same as `self`, `false` otherwise:
877
1016
  #
878
- # /abc/ == /abc/x #=> false
879
- # /abc/ == /abc/i #=> false
880
- # /abc/ == /abc/u #=> false
881
- # /abc/u == /abc/n #=> false
1017
+ # /foo/ == Regexp.new('foo') # => true
1018
+ # /foo/ == /foo/i # => false
1019
+ # /foo/ == Regexp.new('food') # => false
1020
+ # /foo/ == Regexp.new("abc".force_encoding("euc-jp")) # => false
1021
+ #
1022
+ # Regexp#eql? is an alias for Regexp#==.
882
1023
  #
883
1024
  def ==: (untyped other) -> bool
884
1025
 
885
1026
  # <!--
886
1027
  # rdoc-file=re.c
887
- # - rxp === str -> true or false
1028
+ # - regexp === string -> true or false
888
1029
  # -->
889
- # Case Equality---Used in case statements.
1030
+ # Returns `true` if `self` finds a match in `string`:
890
1031
  #
891
- # a = "HELLO"
892
- # case a
893
- # when /\A[a-z]*\z/; print "Lower case\n"
894
- # when /\A[A-Z]*\z/; print "Upper case\n"
895
- # else; print "Mixed case\n"
896
- # end
897
- # #=> "Upper case"
1032
+ # /^[a-z]*$/ === 'HELLO' # => false
1033
+ # /^[A-Z]*$/ === 'HELLO' # => true
898
1034
  #
899
- # Following a regular expression literal with the #=== operator allows you to
900
- # compare against a String.
1035
+ # This method is called in case statements:
901
1036
  #
902
- # /^[a-z]*$/ === "HELLO" #=> false
903
- # /^[A-Z]*$/ === "HELLO" #=> true
1037
+ # s = 'HELLO'
1038
+ # case s
1039
+ # when /\A[a-z]*\z/; print "Lower case\n"
1040
+ # when /\A[A-Z]*\z/; print "Upper case\n"
1041
+ # else print "Mixed case\n"
1042
+ # end # => "Upper case"
904
1043
  #
905
1044
  def ===: (untyped other) -> bool
906
1045
 
907
1046
  # <!--
908
1047
  # rdoc-file=re.c
909
- # - rxp =~ str -> integer or nil
1048
+ # - regexp =~ string -> integer or nil
910
1049
  # -->
911
- # Match---Matches *rxp* against *str*.
1050
+ # Returns the integer index (in characters) of the first match for `self` and
1051
+ # `string`, or `nil` if none; also sets the [rdoc-ref:Regexp Global
1052
+ # Variables](rdoc-ref:Regexp@Regexp+Global+Variables):
1053
+ #
1054
+ # /at/ =~ 'input data' # => 7
1055
+ # $~ # => #<MatchData "at">
1056
+ # /ax/ =~ 'input data' # => nil
1057
+ # $~ # => nil
912
1058
  #
913
- # /at/ =~ "input data" #=> 7
914
- # /ax/ =~ "input data" #=> nil
1059
+ # Assigns named captures to local variables of the same names if and only if
1060
+ # `self`:
915
1061
  #
916
- # If `=~` is used with a regexp literal with named captures, captured strings
917
- # (or nil) is assigned to local variables named by the capture names.
1062
+ # * Is a regexp literal; see [Regexp
1063
+ # Literals](rdoc-ref:literals.rdoc@Regexp+Literals).
1064
+ # * Does not contain interpolations; see [Regexp
1065
+ # Interpolation](rdoc-ref:Regexp@Regexp+Interpolation).
1066
+ # * Is at the left of the expression.
918
1067
  #
919
- # /(?<lhs>\w+)\s*=\s*(?<rhs>\w+)/ =~ " x = y "
920
- # p lhs #=> "x"
921
- # p rhs #=> "y"
922
1068
  #
923
- # If it is not matched, nil is assigned for the variables.
1069
+ # Example:
924
1070
  #
925
- # /(?<lhs>\w+)\s*=\s*(?<rhs>\w+)/ =~ " x = "
926
- # p lhs #=> nil
927
- # p rhs #=> nil
1071
+ # /(?<lhs>\w+)\s*=\s*(?<rhs>\w+)/ =~ ' x = y '
1072
+ # p lhs # => "x"
1073
+ # p rhs # => "y"
928
1074
  #
929
- # This assignment is implemented in the Ruby parser. The parser detects
930
- # 'regexp-literal =~ expression' for the assignment. The regexp must be a
931
- # literal without interpolation and placed at left hand side.
1075
+ # Assigns `nil` if not matched:
932
1076
  #
933
- # The assignment does not occur if the regexp is not a literal.
1077
+ # /(?<lhs>\w+)\s*=\s*(?<rhs>\w+)/ =~ ' x = '
1078
+ # p lhs # => nil
1079
+ # p rhs # => nil
934
1080
  #
935
- # re = /(?<lhs>\w+)\s*=\s*(?<rhs>\w+)/
936
- # re =~ " x = y "
937
- # p lhs # undefined local variable
938
- # p rhs # undefined local variable
1081
+ # Does not make local variable assignments if `self` is not a regexp literal:
939
1082
  #
940
- # A regexp interpolation, `#{}`, also disables the assignment.
1083
+ # r = /(?<foo>\w+)\s*=\s*(?<foo>\w+)/
1084
+ # r =~ ' x = y '
1085
+ # p foo # Undefined local variable
1086
+ # p bar # Undefined local variable
941
1087
  #
942
- # rhs_pat = /(?<rhs>\w+)/
943
- # /(?<lhs>\w+)\s*=\s*#{rhs_pat}/ =~ "x = y"
944
- # p lhs # undefined local variable
1088
+ # The assignment does not occur if the regexp is not at the left:
945
1089
  #
946
- # The assignment does not occur if the regexp is placed at the right hand side.
1090
+ # ' x = y ' =~ /(?<foo>\w+)\s*=\s*(?<foo>\w+)/
1091
+ # p foo, foo # Undefined local variables
947
1092
  #
948
- # " x = y " =~ /(?<lhs>\w+)\s*=\s*(?<rhs>\w+)/
949
- # p lhs, rhs # undefined local variable
1093
+ # A regexp interpolation, `#{}`, also disables the assignment:
950
1094
  #
951
- def =~: (String? str) -> Integer?
1095
+ # r = /(?<foo>\w+)/
1096
+ # /(?<foo>\w+)\s*=\s*#{r}/ =~ 'x = y'
1097
+ # p foo # Undefined local variable
1098
+ #
1099
+ def =~: (String? | Symbol | _ToStr str) -> Integer?
952
1100
 
953
1101
  # <!--
954
1102
  # rdoc-file=re.c
955
- # - rxp.casefold? -> true or false
1103
+ # - casefold?-> true or false
956
1104
  # -->
957
- # Returns the value of the case-insensitive flag.
1105
+ # Returns `true` if the case-insensitivity flag in `self` is set, `false`
1106
+ # otherwise:
958
1107
  #
959
- # /a/.casefold? #=> false
960
- # /a/i.casefold? #=> true
961
- # /(?i:a)/.casefold? #=> false
1108
+ # /a/.casefold? # => false
1109
+ # /a/i.casefold? # => true
1110
+ # /(?i:a)/.casefold? # => false
962
1111
  #
963
1112
  def casefold?: () -> bool
964
1113
 
@@ -972,224 +1121,265 @@ class Regexp
972
1121
 
973
1122
  # <!--
974
1123
  # rdoc-file=re.c
975
- # - rxp == other_rxp -> true or false
976
- # - rxp.eql?(other_rxp) -> true or false
1124
+ # - regexp == object -> true or false
977
1125
  # -->
978
- # Equality---Two regexps are equal if their patterns are identical, they have
979
- # the same character set code, and their `casefold?` values are the same.
1126
+ # Returns `true` if `object` is another Regexp whose pattern, flags, and
1127
+ # encoding are the same as `self`, `false` otherwise:
1128
+ #
1129
+ # /foo/ == Regexp.new('foo') # => true
1130
+ # /foo/ == /foo/i # => false
1131
+ # /foo/ == Regexp.new('food') # => false
1132
+ # /foo/ == Regexp.new("abc".force_encoding("euc-jp")) # => false
980
1133
  #
981
- # /abc/ == /abc/x #=> false
982
- # /abc/ == /abc/i #=> false
983
- # /abc/ == /abc/u #=> false
984
- # /abc/u == /abc/n #=> false
1134
+ # Regexp#eql? is an alias for Regexp#==.
985
1135
  #
986
1136
  def eql?: (untyped other) -> bool
987
1137
 
988
1138
  # <!--
989
1139
  # rdoc-file=re.c
990
- # - rxp.fixed_encoding? -> true or false
1140
+ # - fixed_encoding? -> true or false
991
1141
  # -->
992
- # Returns false if rxp is applicable to a string with any ASCII compatible
993
- # encoding. Returns true otherwise.
994
- #
995
- # r = /a/
996
- # r.fixed_encoding? #=> false
997
- # r =~ "\u{6666} a" #=> 2
998
- # r =~ "\xa1\xa2 a".force_encoding("euc-jp") #=> 2
999
- # r =~ "abc".force_encoding("euc-jp") #=> 0
1000
- #
1001
- # r = /a/u
1002
- # r.fixed_encoding? #=> true
1003
- # r.encoding #=> #<Encoding:UTF-8>
1004
- # r =~ "\u{6666} a" #=> 2
1005
- # r =~ "\xa1\xa2".force_encoding("euc-jp") #=> Encoding::CompatibilityError
1006
- # r =~ "abc".force_encoding("euc-jp") #=> 0
1007
- #
1008
- # r = /\u{6666}/
1009
- # r.fixed_encoding? #=> true
1010
- # r.encoding #=> #<Encoding:UTF-8>
1011
- # r =~ "\u{6666} a" #=> 0
1012
- # r =~ "\xa1\xa2".force_encoding("euc-jp") #=> Encoding::CompatibilityError
1013
- # r =~ "abc".force_encoding("euc-jp") #=> nil
1142
+ # Returns `false` if `self` is applicable to a string with any ASCII-compatible
1143
+ # encoding; otherwise returns `true`:
1144
+ #
1145
+ # r = /a/ # => /a/
1146
+ # r.fixed_encoding? # => false
1147
+ # r.match?("\u{6666} a") # => true
1148
+ # r.match?("\xa1\xa2 a".force_encoding("euc-jp")) # => true
1149
+ # r.match?("abc".force_encoding("euc-jp")) # => true
1150
+ #
1151
+ # r = /a/u # => /a/
1152
+ # r.fixed_encoding? # => true
1153
+ # r.match?("\u{6666} a") # => true
1154
+ # r.match?("\xa1\xa2".force_encoding("euc-jp")) # Raises exception.
1155
+ # r.match?("abc".force_encoding("euc-jp")) # => true
1156
+ #
1157
+ # r = /\u{6666}/ # => /\u{6666}/
1158
+ # r.fixed_encoding? # => true
1159
+ # r.encoding # => #<Encoding:UTF-8>
1160
+ # r.match?("\u{6666} a") # => true
1161
+ # r.match?("\xa1\xa2".force_encoding("euc-jp")) # Raises exception.
1162
+ # r.match?("abc".force_encoding("euc-jp")) # => false
1014
1163
  #
1015
1164
  def fixed_encoding?: () -> bool
1016
1165
 
1017
1166
  # <!--
1018
1167
  # rdoc-file=re.c
1019
- # - rxp.hash -> integer
1168
+ # - hash -> integer
1020
1169
  # -->
1021
- # Produce a hash based on the text and options of this regular expression.
1170
+ # Returns the integer hash value for `self`.
1022
1171
  #
1023
- # See also Object#hash.
1172
+ # Related: Object#hash.
1024
1173
  #
1025
1174
  def hash: () -> Integer
1026
1175
 
1027
1176
  # <!--
1028
1177
  # rdoc-file=re.c
1029
- # - rxp.inspect -> string
1178
+ # - inspect -> string
1030
1179
  # -->
1031
- # Produce a nicely formatted string-version of *rxp*. Perhaps surprisingly,
1032
- # `#inspect` actually produces the more natural version of the string than
1033
- # `#to_s`.
1180
+ # Returns a nicely-formatted string representation of `self`:
1181
+ #
1182
+ # /ab+c/ix.inspect # => "/ab+c/ix"
1034
1183
  #
1035
- # /ab+c/ix.inspect #=> "/ab+c/ix"
1184
+ # Related: Regexp#to_s.
1036
1185
  #
1037
1186
  def inspect: () -> String
1038
1187
 
1039
1188
  # <!--
1040
1189
  # rdoc-file=re.c
1041
- # - rxp.match(str, pos=0) -> matchdata or nil
1042
- # - rxp.match(str, pos=0) {|match| block } -> obj
1190
+ # - match(string, offset = 0) -> matchdata or nil
1191
+ # - match(string, offset = 0) {|matchdata| ... } -> object
1043
1192
  # -->
1044
- # Returns a MatchData object describing the match, or `nil` if there was no
1045
- # match. This is equivalent to retrieving the value of the special variable `$~`
1046
- # following a normal match. If the second parameter is present, it specifies
1047
- # the position in the string to begin the search.
1193
+ # With no block given, returns the MatchData object that describes the match, if
1194
+ # any, or `nil` if none; the search begins at the given character `offset` in
1195
+ # `string`:
1048
1196
  #
1049
- # /(.)(.)(.)/.match("abc")[2] #=> "b"
1050
- # /(.)(.)/.match("abc", 1)[2] #=> "c"
1197
+ # /abra/.match('abracadabra') # => #<MatchData "abra">
1198
+ # /abra/.match('abracadabra', 4) # => #<MatchData "abra">
1199
+ # /abra/.match('abracadabra', 8) # => nil
1200
+ # /abra/.match('abracadabra', 800) # => nil
1051
1201
  #
1052
- # If a block is given, invoke the block with MatchData if match succeed, so that
1053
- # you can write
1202
+ # string = "\u{5d0 5d1 5e8 5d0}cadabra"
1203
+ # /abra/.match(string, 7) #=> #<MatchData "abra">
1204
+ # /abra/.match(string, 8) #=> nil
1205
+ # /abra/.match(string.b, 8) #=> #<MatchData "abra">
1054
1206
  #
1055
- # /M(.*)/.match("Matz") do |m|
1056
- # puts m[0]
1057
- # puts m[1]
1058
- # end
1207
+ # With a block given, calls the block if and only if a match is found; returns
1208
+ # the block's value:
1059
1209
  #
1060
- # instead of
1210
+ # /abra/.match('abracadabra') {|matchdata| p matchdata }
1211
+ # # => #<MatchData "abra">
1212
+ # /abra/.match('abracadabra', 4) {|matchdata| p matchdata }
1213
+ # # => #<MatchData "abra">
1214
+ # /abra/.match('abracadabra', 8) {|matchdata| p matchdata }
1215
+ # # => nil
1216
+ # /abra/.match('abracadabra', 8) {|marchdata| fail 'Cannot happen' }
1217
+ # # => nil
1061
1218
  #
1062
- # if m = /M(.*)/.match("Matz")
1063
- # puts m[0]
1064
- # puts m[1]
1065
- # end
1219
+ # Output (from the first two blocks above):
1066
1220
  #
1067
- # The return value is a value from block execution in this case.
1221
+ # #<MatchData "abra">
1222
+ # #<MatchData "abra">
1223
+ #
1224
+ # /(.)(.)(.)/.match("abc")[2] # => "b"
1225
+ # /(.)(.)/.match("abc", 1)[2] # => "c"
1068
1226
  #
1069
1227
  def match: (String? | Symbol | _ToStr str, ?Integer pos) -> MatchData?
1070
1228
  | [T] (String? | Symbol | _ToStr str, ?Integer pos) { (MatchData) -> T } -> T?
1071
1229
 
1072
1230
  # <!--
1073
1231
  # rdoc-file=re.c
1074
- # - rxp.match?(str) -> true or false
1075
- # - rxp.match?(str, pos=0) -> true or false
1232
+ # - match?(string) -> true or false
1233
+ # - match?(string, offset = 0) -> true or false
1076
1234
  # -->
1077
1235
  # Returns `true` or `false` to indicate whether the regexp is matched or not
1078
1236
  # without updating $~ and other related variables. If the second parameter is
1079
1237
  # present, it specifies the position in the string to begin the search.
1080
1238
  #
1081
- # /R.../.match?("Ruby") #=> true
1082
- # /R.../.match?("Ruby", 1) #=> false
1083
- # /P.../.match?("Ruby") #=> false
1084
- # $& #=> nil
1239
+ # /R.../.match?("Ruby") # => true
1240
+ # /R.../.match?("Ruby", 1) # => false
1241
+ # /P.../.match?("Ruby") # => false
1242
+ # $& # => nil
1085
1243
  #
1086
1244
  def match?: (String? | Symbol | _ToStr str, ?Integer pos) -> bool
1087
1245
 
1088
1246
  # <!--
1089
1247
  # rdoc-file=re.c
1090
- # - rxp.named_captures -> hash
1248
+ # - named_captures -> hash
1091
1249
  # -->
1092
- # Returns a hash representing information about named captures of *rxp*.
1093
- #
1094
- # A key of the hash is a name of the named captures. A value of the hash is an
1095
- # array which is list of indexes of corresponding named captures.
1250
+ # Returns a hash representing named captures of `self` (see [Named
1251
+ # Captures](rdoc-ref:Regexp@Named+Captures)):
1096
1252
  #
1097
- # /(?<foo>.)(?<bar>.)/.named_captures
1098
- # #=> {"foo"=>[1], "bar"=>[2]}
1253
+ # * Each key is the name of a named capture.
1254
+ # * Each value is an array of integer indexes for that named capture.
1099
1255
  #
1100
- # /(?<foo>.)(?<foo>.)/.named_captures
1101
- # #=> {"foo"=>[1, 2]}
1102
1256
  #
1103
- # If there are no named captures, an empty hash is returned.
1257
+ # Examples:
1104
1258
  #
1105
- # /(.)(.)/.named_captures
1106
- # #=> {}
1259
+ # /(?<foo>.)(?<bar>.)/.named_captures # => {"foo"=>[1], "bar"=>[2]}
1260
+ # /(?<foo>.)(?<foo>.)/.named_captures # => {"foo"=>[1, 2]}
1261
+ # /(.)(.)/.named_captures # => {}
1107
1262
  #
1108
1263
  def named_captures: () -> ::Hash[String, ::Array[Integer]]
1109
1264
 
1110
1265
  # <!--
1111
1266
  # rdoc-file=re.c
1112
- # - rxp.names -> [name1, name2, ...]
1267
+ # - names -> array_of_names
1113
1268
  # -->
1114
- # Returns a list of names of captures as an array of strings.
1115
- #
1116
- # /(?<foo>.)(?<bar>.)(?<baz>.)/.names
1117
- # #=> ["foo", "bar", "baz"]
1118
- #
1119
- # /(?<foo>.)(?<foo>.)/.names
1120
- # #=> ["foo"]
1269
+ # Returns an array of names of captures (see [Named
1270
+ # Captures](rdoc-ref:Regexp@Named+Captures)):
1121
1271
  #
1122
- # /(.)(.)/.names
1123
- # #=> []
1272
+ # /(?<foo>.)(?<bar>.)(?<baz>.)/.names # => ["foo", "bar", "baz"]
1273
+ # /(?<foo>.)(?<foo>.)/.names # => ["foo"]
1274
+ # /(.)(.)/.names # => []
1124
1275
  #
1125
1276
  def names: () -> ::Array[String]
1126
1277
 
1127
1278
  # <!--
1128
1279
  # rdoc-file=re.c
1129
- # - rxp.options -> integer
1280
+ # - options -> integer
1130
1281
  # -->
1131
- # Returns the set of bits corresponding to the options used when creating this
1132
- # Regexp (see Regexp::new for details. Note that additional bits may be set in
1133
- # the returned options: these are used internally by the regular expression
1134
- # code. These extra bits are ignored if the options are passed to Regexp::new.
1282
+ # Returns an integer whose bits show the options set in `self`.
1283
+ #
1284
+ # The option bits are:
1135
1285
  #
1136
- # Regexp::IGNORECASE #=> 1
1137
- # Regexp::EXTENDED #=> 2
1138
- # Regexp::MULTILINE #=> 4
1286
+ # Regexp::IGNORECASE # => 1
1287
+ # Regexp::EXTENDED # => 2
1288
+ # Regexp::MULTILINE # => 4
1139
1289
  #
1140
- # /cat/.options #=> 0
1141
- # /cat/ix.options #=> 3
1142
- # Regexp.new('cat', true).options #=> 1
1143
- # /\xa1\xa2/e.options #=> 16
1290
+ # Examples:
1144
1291
  #
1145
- # r = /cat/ix
1146
- # Regexp.new(r.source, r.options) #=> /cat/ix
1292
+ # /foo/.options # => 0
1293
+ # /foo/i.options # => 1
1294
+ # /foo/x.options # => 2
1295
+ # /foo/m.options # => 4
1296
+ # /foo/mix.options # => 7
1297
+ #
1298
+ # Note that additional bits may be set in the returned integer; these are
1299
+ # maintained internally internally in `self`, are ignored if passed to
1300
+ # Regexp.new, and may be ignored by the caller:
1301
+ #
1302
+ # Returns the set of bits corresponding to the options used when creating this
1303
+ # regexp (see Regexp::new for details). Note that additional bits may be set in
1304
+ # the returned options: these are used internally by the regular expression
1305
+ # code. These extra bits are ignored if the options are passed to Regexp::new:
1306
+ #
1307
+ # r = /\xa1\xa2/e # => /\xa1\xa2/
1308
+ # r.source # => "\\xa1\\xa2"
1309
+ # r.options # => 16
1310
+ # Regexp.new(r.source, r.options) # => /\xa1\xa2/
1147
1311
  #
1148
1312
  def options: () -> Integer
1149
1313
 
1150
1314
  # <!--
1151
1315
  # rdoc-file=re.c
1152
- # - rxp.source -> str
1316
+ # - source -> string
1153
1317
  # -->
1154
- # Returns the original string of the pattern.
1318
+ # Returns the original string of `self`:
1319
+ #
1320
+ # /ab+c/ix.source # => "ab+c"
1321
+ #
1322
+ # Regexp escape sequences are retained:
1155
1323
  #
1156
- # /ab+c/ix.source #=> "ab+c"
1324
+ # /\x20\+/.source # => "\\x20\\+"
1157
1325
  #
1158
- # Note that escape sequences are retained as is.
1326
+ # Lexer escape characters are not retained:
1159
1327
  #
1160
- # /\x20\+/.source #=> "\\x20\\+"
1328
+ # /\//.source # => "/"
1161
1329
  #
1162
1330
  def source: () -> String
1163
1331
 
1164
1332
  # <!--
1165
1333
  # rdoc-file=re.c
1166
- # - rxp.to_s -> str
1334
+ # - to_s -> string
1167
1335
  # -->
1168
- # Returns a string containing the regular expression and its options (using the
1169
- # `(?opts:source)` notation. This string can be fed back in to Regexp::new to a
1170
- # regular expression with the same semantics as the original. (However,
1171
- # `Regexp#==` may not return true when comparing the two, as the source of the
1172
- # regular expression itself may differ, as the example shows). Regexp#inspect
1173
- # produces a generally more readable version of *rxp*.
1174
- #
1175
- # r1 = /ab+c/ix #=> /ab+c/ix
1176
- # s1 = r1.to_s #=> "(?ix-m:ab+c)"
1177
- # r2 = Regexp.new(s1) #=> /(?ix-m:ab+c)/
1178
- # r1 == r2 #=> false
1179
- # r1.source #=> "ab+c"
1180
- # r2.source #=> "(?ix-m:ab+c)"
1336
+ # Returns a string showing the options and string of `self`:
1337
+ #
1338
+ # r0 = /ab+c/ix
1339
+ # s0 = r0.to_s # => "(?ix-m:ab+c)"
1340
+ #
1341
+ # The returned string may be used as an argument to Regexp.new, or as
1342
+ # interpolated text for a [Regexp literal](rdoc-ref:regexp.rdoc@Regexp+Literal):
1343
+ #
1344
+ # r1 = Regexp.new(s0) # => /(?ix-m:ab+c)/
1345
+ # r2 = /#{s0}/ # => /(?ix-m:ab+c)/
1346
+ #
1347
+ # Note that `r1` and `r2` are not equal to `r0` because their original strings
1348
+ # are different:
1349
+ #
1350
+ # r0 == r1 # => false
1351
+ # r0.source # => "ab+c"
1352
+ # r1.source # => "(?ix-m:ab+c)"
1353
+ #
1354
+ # Related: Regexp#inspect.
1181
1355
  #
1182
1356
  def to_s: () -> String
1183
1357
 
1184
1358
  # <!--
1185
1359
  # rdoc-file=re.c
1186
- # - ~ rxp -> integer or nil
1360
+ # - rxp.timeout -> float or nil
1361
+ # -->
1362
+ # It returns the timeout interval for Regexp matching in second. `nil` means no
1363
+ # default timeout configuration.
1364
+ #
1365
+ # This configuration is per-object. The global configuration set by
1366
+ # Regexp.timeout= is ignored if per-object configuration is set.
1367
+ #
1368
+ # re = Regexp.new("^a*b?a*$", timeout: 1)
1369
+ # re.timeout #=> 1.0
1370
+ # re =~ "a" * 100000 + "x" #=> regexp match timeout (RuntimeError)
1371
+ #
1372
+ %a{pure}
1373
+ def timeout: () -> Float?
1374
+
1375
+ # <!--
1376
+ # rdoc-file=re.c
1377
+ # - ~ rxp -> integer or nil
1187
1378
  # -->
1188
- # Match---Matches *rxp* against the contents of `$_`. Equivalent to *`rxp* =~
1189
- # $_`.
1379
+ # Equivalent to *`rxp* =~ $_`:
1190
1380
  #
1191
1381
  # $_ = "input data"
1192
- # ~ /at/ #=> 7
1382
+ # ~ /at/ # => 7
1193
1383
  #
1194
1384
  def ~: () -> Integer?
1195
1385