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.
- checksums.yaml +4 -4
- data/.github/workflows/comments.yml +2 -1
- data/.github/workflows/ruby.yml +4 -0
- data/Gemfile.lock +11 -11
- data/Rakefile +2 -2
- data/Steepfile +1 -1
- data/core/array.rbs +573 -423
- data/core/basic_object.rbs +11 -39
- data/core/binding.rbs +1 -1
- data/core/builtin.rbs +8 -0
- data/core/class.rbs +37 -0
- data/core/comparable.rbs +7 -18
- data/core/complex.rbs +2 -2
- data/core/data.rbs +419 -0
- data/core/dir.rbs +52 -104
- data/core/encoding.rbs +22 -181
- data/core/enumerable.rbs +212 -175
- data/core/enumerator/product.rbs +96 -0
- data/core/enumerator.rbs +57 -8
- data/core/errors.rbs +8 -2
- data/core/exception.rbs +41 -0
- data/core/fiber.rbs +95 -12
- data/core/file.rbs +840 -275
- data/core/file_test.rbs +34 -19
- data/core/float.rbs +40 -96
- data/core/gc.rbs +15 -3
- data/core/hash.rbs +113 -175
- data/core/integer.rbs +85 -145
- data/core/io/buffer.rbs +187 -60
- data/core/io/wait.rbs +28 -16
- data/core/io.rbs +1859 -1389
- data/core/kernel.rbs +525 -961
- data/core/match_data.rbs +306 -142
- data/core/math.rbs +506 -234
- data/core/method.rbs +0 -24
- data/core/module.rbs +110 -17
- data/core/nil_class.rbs +2 -0
- data/core/numeric.rbs +76 -144
- data/core/object.rbs +88 -212
- data/core/proc.rbs +17 -5
- data/core/process.rbs +22 -5
- data/core/ractor.rbs +1 -1
- data/core/random.rbs +20 -3
- data/core/range.rbs +91 -89
- data/core/rational.rbs +2 -3
- data/core/rbs/unnamed/argf.rbs +177 -120
- data/core/rbs/unnamed/env_class.rbs +89 -163
- data/core/rbs/unnamed/random.rbs +36 -12
- data/core/refinement.rbs +8 -0
- data/core/regexp.rbs +462 -272
- data/core/ruby_vm.rbs +210 -0
- data/{stdlib/set/0 → core}/set.rbs +43 -47
- data/core/string.rbs +1403 -1332
- data/core/string_io.rbs +191 -107
- data/core/struct.rbs +67 -63
- data/core/symbol.rbs +187 -201
- data/core/thread.rbs +40 -35
- data/core/time.rbs +902 -826
- data/core/trace_point.rbs +55 -6
- data/core/unbound_method.rbs +48 -24
- data/docs/collection.md +4 -0
- data/docs/syntax.md +55 -0
- data/ext/rbs_extension/parser.c +5 -6
- data/lib/rbs/cli.rb +6 -1
- data/lib/rbs/collection/cleaner.rb +8 -1
- data/lib/rbs/collection/config/lockfile.rb +3 -1
- data/lib/rbs/collection/config/lockfile_generator.rb +16 -14
- data/lib/rbs/collection/config.rb +1 -1
- data/lib/rbs/collection/sources/git.rb +9 -2
- data/lib/rbs/collection/sources/local.rb +79 -0
- data/lib/rbs/collection/sources.rb +8 -1
- data/lib/rbs/environment.rb +6 -5
- data/lib/rbs/environment_loader.rb +3 -2
- data/lib/rbs/errors.rb +18 -0
- data/lib/rbs/locator.rb +26 -7
- data/lib/rbs/sorter.rb +2 -2
- data/lib/rbs/version.rb +1 -1
- data/sig/collection/sources.rbs +32 -3
- data/sig/environment.rbs +2 -3
- data/sig/locator.rbs +14 -2
- data/sig/shims/{abstract_syntax_tree.rbs → _abstract_syntax_tree.rbs} +0 -0
- data/stdlib/bigdecimal/0/big_decimal.rbs +16 -13
- data/stdlib/cgi/0/core.rbs +16 -0
- data/stdlib/coverage/0/coverage.rbs +50 -8
- data/stdlib/csv/0/csv.rbs +1 -1
- data/stdlib/date/0/date.rbs +856 -726
- data/stdlib/date/0/date_time.rbs +83 -210
- data/stdlib/erb/0/erb.rbs +13 -36
- data/stdlib/etc/0/etc.rbs +127 -20
- data/stdlib/fileutils/0/fileutils.rbs +1290 -381
- data/stdlib/logger/0/logger.rbs +466 -316
- data/stdlib/net-http/0/net-http.rbs +2211 -534
- data/stdlib/nkf/0/nkf.rbs +5 -5
- data/stdlib/objspace/0/objspace.rbs +31 -14
- data/stdlib/openssl/0/openssl.rbs +11 -7
- data/stdlib/optparse/0/optparse.rbs +20 -17
- data/stdlib/pathname/0/pathname.rbs +21 -4
- data/stdlib/pstore/0/pstore.rbs +378 -154
- data/stdlib/pty/0/pty.rbs +24 -8
- data/stdlib/ripper/0/ripper.rbs +1650 -0
- data/stdlib/socket/0/addrinfo.rbs +9 -15
- data/stdlib/socket/0/socket.rbs +36 -3
- data/stdlib/strscan/0/string_scanner.rbs +7 -5
- data/stdlib/tempfile/0/tempfile.rbs +104 -44
- data/stdlib/time/0/time.rbs +2 -2
- data/stdlib/uri/0/file.rbs +5 -0
- data/stdlib/uri/0/generic.rbs +2 -2
- data/stdlib/yaml/0/yaml.rbs +2 -2
- data/stdlib/zlib/0/zlib.rbs +1 -1
- metadata +8 -6
- data/core/deprecated.rbs +0 -9
- 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
|
-
# ### `=~`
|
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
|
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
|
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
|
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
|
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
|
-
#
|
530
|
-
#
|
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
|
-
# ##
|
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,
|
745
|
-
# - Regexp.new(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
|
-
#
|
750
|
-
#
|
751
|
-
#
|
752
|
-
#
|
753
|
-
#
|
754
|
-
#
|
755
|
-
#
|
756
|
-
#
|
757
|
-
#
|
758
|
-
#
|
759
|
-
#
|
760
|
-
#
|
761
|
-
#
|
762
|
-
#
|
763
|
-
|
764
|
-
|
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(
|
777
|
-
# - Regexp.quote(str) -> string
|
838
|
+
# - Regexp.escape(string) -> new_string
|
778
839
|
# -->
|
779
|
-
#
|
780
|
-
#
|
781
|
-
#
|
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
|
-
#
|
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
|
790
|
-
# - Regexp.last_match(n)
|
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
|
-
#
|
793
|
-
# pattern match
|
794
|
-
#
|
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
|
-
#
|
797
|
-
#
|
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
|
-
#
|
800
|
-
# that did the pattern match.
|
877
|
+
# With negative integer argument `n`, counts backwards from the last field:
|
801
878
|
#
|
802
|
-
#
|
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
|
-
#
|
809
|
-
#
|
810
|
-
#
|
811
|
-
#
|
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.
|
820
|
-
# - Regexp.
|
896
|
+
# - Regexp.linear_time?(re)
|
897
|
+
# - Regexp.linear_time?(string, options = 0)
|
821
898
|
# -->
|
822
|
-
#
|
823
|
-
#
|
824
|
-
#
|
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
|
-
#
|
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(
|
935
|
+
# - Regexp.try_convert(object) -> regexp or nil
|
833
936
|
# -->
|
834
|
-
#
|
835
|
-
#
|
937
|
+
# Returns `object` if it is a regexp:
|
938
|
+
#
|
939
|
+
# Regexp.try_convert(/re/) # => /re/
|
836
940
|
#
|
837
|
-
#
|
838
|
-
#
|
941
|
+
# Otherwise if `object` responds to `:to_regexp`, calls `object.to_regexp` and
|
942
|
+
# returns the result.
|
839
943
|
#
|
840
|
-
#
|
841
|
-
#
|
842
|
-
#
|
843
|
-
#
|
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.
|
850
|
-
#
|
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
|
-
#
|
853
|
-
#
|
854
|
-
#
|
855
|
-
#
|
856
|
-
#
|
857
|
-
#
|
858
|
-
#
|
859
|
-
#
|
860
|
-
#
|
861
|
-
# Regexp.union(
|
862
|
-
# Regexp.union(
|
863
|
-
# Regexp.union(
|
864
|
-
#
|
865
|
-
#
|
866
|
-
#
|
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
|
-
#
|
876
|
-
# 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
|
-
# /
|
879
|
-
# /
|
880
|
-
# /
|
881
|
-
# /
|
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
|
-
# -
|
1028
|
+
# - regexp === string -> true or false
|
888
1029
|
# -->
|
889
|
-
#
|
1030
|
+
# Returns `true` if `self` finds a match in `string`:
|
890
1031
|
#
|
891
|
-
# a
|
892
|
-
#
|
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
|
-
#
|
900
|
-
# compare against a String.
|
1035
|
+
# This method is called in case statements:
|
901
1036
|
#
|
902
|
-
#
|
903
|
-
#
|
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
|
-
# -
|
1048
|
+
# - regexp =~ string -> integer or nil
|
910
1049
|
# -->
|
911
|
-
#
|
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
|
-
#
|
914
|
-
#
|
1059
|
+
# Assigns named captures to local variables of the same names if and only if
|
1060
|
+
# `self`:
|
915
1061
|
#
|
916
|
-
#
|
917
|
-
#
|
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
|
-
#
|
1069
|
+
# Example:
|
924
1070
|
#
|
925
|
-
# /(?<lhs>\w+)\s*=\s*(?<rhs>\w+)/ =~
|
926
|
-
# p lhs
|
927
|
-
# p rhs
|
1071
|
+
# /(?<lhs>\w+)\s*=\s*(?<rhs>\w+)/ =~ ' x = y '
|
1072
|
+
# p lhs # => "x"
|
1073
|
+
# p rhs # => "y"
|
928
1074
|
#
|
929
|
-
#
|
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
|
-
#
|
1077
|
+
# /(?<lhs>\w+)\s*=\s*(?<rhs>\w+)/ =~ ' x = '
|
1078
|
+
# p lhs # => nil
|
1079
|
+
# p rhs # => nil
|
934
1080
|
#
|
935
|
-
#
|
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
|
-
#
|
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
|
-
#
|
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
|
-
#
|
1090
|
+
# ' x = y ' =~ /(?<foo>\w+)\s*=\s*(?<foo>\w+)/
|
1091
|
+
# p foo, foo # Undefined local variables
|
947
1092
|
#
|
948
|
-
#
|
949
|
-
# p lhs, rhs # undefined local variable
|
1093
|
+
# A regexp interpolation, `#{}`, also disables the assignment:
|
950
1094
|
#
|
951
|
-
|
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
|
-
# -
|
1103
|
+
# - casefold?-> true or false
|
956
1104
|
# -->
|
957
|
-
# Returns
|
1105
|
+
# Returns `true` if the case-insensitivity flag in `self` is set, `false`
|
1106
|
+
# otherwise:
|
958
1107
|
#
|
959
|
-
# /a/.casefold?
|
960
|
-
# /a/i.casefold?
|
961
|
-
# /(?i:a)/.casefold?
|
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
|
-
# -
|
976
|
-
# - rxp.eql?(other_rxp) -> true or false
|
1124
|
+
# - regexp == object -> true or false
|
977
1125
|
# -->
|
978
|
-
#
|
979
|
-
# 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
|
-
#
|
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
|
-
# -
|
1140
|
+
# - fixed_encoding? -> true or false
|
991
1141
|
# -->
|
992
|
-
# Returns false if
|
993
|
-
# encoding
|
994
|
-
#
|
995
|
-
# r = /a/
|
996
|
-
# r.fixed_encoding?
|
997
|
-
# r
|
998
|
-
# r
|
999
|
-
# r
|
1000
|
-
#
|
1001
|
-
# r = /a/u
|
1002
|
-
# r.fixed_encoding?
|
1003
|
-
# r.
|
1004
|
-
# r
|
1005
|
-
# r
|
1006
|
-
#
|
1007
|
-
#
|
1008
|
-
# r
|
1009
|
-
# r.
|
1010
|
-
# r.
|
1011
|
-
# r
|
1012
|
-
# r
|
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
|
-
# -
|
1168
|
+
# - hash -> integer
|
1020
1169
|
# -->
|
1021
|
-
#
|
1170
|
+
# Returns the integer hash value for `self`.
|
1022
1171
|
#
|
1023
|
-
#
|
1172
|
+
# Related: Object#hash.
|
1024
1173
|
#
|
1025
1174
|
def hash: () -> Integer
|
1026
1175
|
|
1027
1176
|
# <!--
|
1028
1177
|
# rdoc-file=re.c
|
1029
|
-
# -
|
1178
|
+
# - inspect -> string
|
1030
1179
|
# -->
|
1031
|
-
#
|
1032
|
-
#
|
1033
|
-
#
|
1180
|
+
# Returns a nicely-formatted string representation of `self`:
|
1181
|
+
#
|
1182
|
+
# /ab+c/ix.inspect # => "/ab+c/ix"
|
1034
1183
|
#
|
1035
|
-
#
|
1184
|
+
# Related: Regexp#to_s.
|
1036
1185
|
#
|
1037
1186
|
def inspect: () -> String
|
1038
1187
|
|
1039
1188
|
# <!--
|
1040
1189
|
# rdoc-file=re.c
|
1041
|
-
# -
|
1042
|
-
# -
|
1190
|
+
# - match(string, offset = 0) -> matchdata or nil
|
1191
|
+
# - match(string, offset = 0) {|matchdata| ... } -> object
|
1043
1192
|
# -->
|
1044
|
-
#
|
1045
|
-
#
|
1046
|
-
#
|
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
|
-
# /
|
1050
|
-
# /
|
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
|
-
#
|
1053
|
-
#
|
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
|
-
#
|
1056
|
-
#
|
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
|
-
#
|
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
|
-
#
|
1063
|
-
# puts m[0]
|
1064
|
-
# puts m[1]
|
1065
|
-
# end
|
1219
|
+
# Output (from the first two blocks above):
|
1066
1220
|
#
|
1067
|
-
#
|
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
|
-
# -
|
1075
|
-
# -
|
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")
|
1082
|
-
# /R.../.match?("Ruby", 1)
|
1083
|
-
# /P.../.match?("Ruby")
|
1084
|
-
# $&
|
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
|
-
# -
|
1248
|
+
# - named_captures -> hash
|
1091
1249
|
# -->
|
1092
|
-
# Returns a hash representing
|
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
|
-
#
|
1098
|
-
#
|
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
|
-
#
|
1257
|
+
# Examples:
|
1104
1258
|
#
|
1105
|
-
# /(
|
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
|
-
# -
|
1267
|
+
# - names -> array_of_names
|
1113
1268
|
# -->
|
1114
|
-
# Returns
|
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
|
-
# /(
|
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
|
-
# -
|
1280
|
+
# - options -> integer
|
1130
1281
|
# -->
|
1131
|
-
# Returns
|
1132
|
-
#
|
1133
|
-
#
|
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
|
1137
|
-
# Regexp::EXTENDED
|
1138
|
-
# Regexp::MULTILINE
|
1286
|
+
# Regexp::IGNORECASE # => 1
|
1287
|
+
# Regexp::EXTENDED # => 2
|
1288
|
+
# Regexp::MULTILINE # => 4
|
1139
1289
|
#
|
1140
|
-
#
|
1141
|
-
# /cat/ix.options #=> 3
|
1142
|
-
# Regexp.new('cat', true).options #=> 1
|
1143
|
-
# /\xa1\xa2/e.options #=> 16
|
1290
|
+
# Examples:
|
1144
1291
|
#
|
1145
|
-
#
|
1146
|
-
#
|
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
|
-
# -
|
1316
|
+
# - source -> string
|
1153
1317
|
# -->
|
1154
|
-
# Returns the original string of
|
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
|
-
#
|
1324
|
+
# /\x20\+/.source # => "\\x20\\+"
|
1157
1325
|
#
|
1158
|
-
#
|
1326
|
+
# Lexer escape characters are not retained:
|
1159
1327
|
#
|
1160
|
-
#
|
1328
|
+
# /\//.source # => "/"
|
1161
1329
|
#
|
1162
1330
|
def source: () -> String
|
1163
1331
|
|
1164
1332
|
# <!--
|
1165
1333
|
# rdoc-file=re.c
|
1166
|
-
# -
|
1334
|
+
# - to_s -> string
|
1167
1335
|
# -->
|
1168
|
-
# Returns a string
|
1169
|
-
#
|
1170
|
-
#
|
1171
|
-
#
|
1172
|
-
#
|
1173
|
-
#
|
1174
|
-
#
|
1175
|
-
#
|
1176
|
-
#
|
1177
|
-
# r2 =
|
1178
|
-
#
|
1179
|
-
#
|
1180
|
-
#
|
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
|
-
# -
|
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
|
-
#
|
1189
|
-
# $_`.
|
1379
|
+
# Equivalent to *`rxp* =~ $_`:
|
1190
1380
|
#
|
1191
1381
|
# $_ = "input data"
|
1192
|
-
# ~ /at/
|
1382
|
+
# ~ /at/ # => 7
|
1193
1383
|
#
|
1194
1384
|
def ~: () -> Integer?
|
1195
1385
|
|