Skip to content

Commit 86ca61c

Browse files
authored
Merge pull request #2146 from ParadoxV5/string-scan-nil-group
Core: `String#scan` groups may be nil
2 parents e21a8b7 + 152c4e6 commit 86ca61c

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

core/string.rbs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2733,8 +2733,8 @@ class String
27332733
# <<cruel>> <<world>>
27342734
# rceu lowlr
27352735
#
2736-
def scan: (Regexp pattern) -> Array[String | Array[String]]
2737-
| (Regexp pattern) { (String | Array[String] matches) -> void } -> self
2736+
def scan: (Regexp pattern) -> Array[String | Array[String?]]
2737+
| (Regexp pattern) { (String | Array[String?] matches) -> void } -> self
27382738
| (string pattern) -> Array[String]
27392739
| (string pattern) { (String match) -> void } -> self
27402740

test/stdlib/String_test.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1259,11 +1259,15 @@ def test_scan
12591259
'hello', :scan, /l/
12601260
assert_send_type '(Regexp) -> Array[Array[String]]',
12611261
'hello', :scan, /(l)/
1262+
assert_send_type '(Regexp) -> Array[Array[nil]]',
1263+
'hello', :scan, /(x)?/
12621264

12631265
assert_send_type '(Regexp) { (String) -> void } -> String',
12641266
'hello', :scan, /l/ do end
12651267
assert_send_type '(Regexp) { (Array[String]) -> void } -> String',
12661268
'hello', :scan, /(l)/ do end
1269+
assert_send_type '(Regexp) { (Array[nil]) -> void } -> String',
1270+
'hello', :scan, /(x)?/ do end
12671271

12681272
with_string 'l' do |pattern|
12691273
assert_send_type '(string) -> Array[String]',

0 commit comments

Comments
 (0)