Skip to content

Commit fdfffb3

Browse files
authored
Merge pull request #2775 from ksss/string-strip-selector
Support selector for `String#strip` family.
2 parents 25bc260 + 3a85d0b commit fdfffb3

File tree

2 files changed

+48
-6
lines changed

2 files changed

+48
-6
lines changed

core/string.rbs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3670,7 +3670,7 @@ class String
36703670
# Related: see [Converting to New
36713671
# String](rdoc-ref:String@Converting+to+New+String).
36723672
#
3673-
def lstrip: () -> String
3673+
def lstrip: (*selector) -> String
36743674

36753675
# <!--
36763676
# rdoc-file=string.c
@@ -3683,7 +3683,7 @@ class String
36833683
#
36843684
# Related: see [Modifying](rdoc-ref:String@Modifying).
36853685
#
3686-
def lstrip!: () -> self?
3686+
def lstrip!: (*selector) -> self?
36873687

36883688
# <!--
36893689
# rdoc-file=string.c
@@ -4195,7 +4195,7 @@ class String
41954195
# Related: see [Converting to New
41964196
# String](rdoc-ref:String@Converting+to+New+String).
41974197
#
4198-
def rstrip: () -> String
4198+
def rstrip: (*selector) -> String
41994199

42004200
# <!--
42014201
# rdoc-file=string.c
@@ -4208,7 +4208,7 @@ class String
42084208
#
42094209
# Related: see [Modifying](rdoc-ref:String@Modifying).
42104210
#
4211-
def rstrip!: () -> self?
4211+
def rstrip!: (*selector) -> self?
42124212

42134213
# <!--
42144214
# rdoc-file=string.c
@@ -4681,7 +4681,7 @@ class String
46814681
# Related: see [Converting to New
46824682
# String](rdoc-ref:String@Converting+to+New+String).
46834683
#
4684-
def strip: () -> String
4684+
def strip: (*selector) -> String
46854685

46864686
# <!--
46874687
# rdoc-file=string.c
@@ -4694,7 +4694,7 @@ class String
46944694
#
46954695
# Related: see [Modifying](rdoc-ref:String@Modifying).
46964696
#
4697-
def strip!: () -> self?
4697+
def strip!: (*selector) -> self?
46984698

46994699
# <!--
47004700
# rdoc-file=string.c

test/stdlib/String_test.rb

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1099,13 +1099,27 @@ def test_lstrip
10991099
' hello', :lstrip
11001100
assert_send_type '() -> String',
11011101
'hello', :lstrip
1102+
1103+
if_ruby("4.0"...) do
1104+
with_string "0-9" do |selector|
1105+
assert_send_type '(String::selector) -> String',
1106+
"01234abc56789", :lstrip, selector
1107+
end
1108+
end
11021109
end
11031110

11041111
def test_lstrip!
11051112
assert_send_type '() -> String',
11061113
+' hello', :lstrip!
11071114
assert_send_type '() -> nil',
11081115
+'hello', :lstrip!
1116+
1117+
if_ruby("4.0"...) do
1118+
with_string "0-9" do |selector|
1119+
assert_send_type '(String::selector) -> String',
1120+
"01234abc56789", :lstrip!, selector
1121+
end
1122+
end
11091123
end
11101124

11111125
def test_match
@@ -1252,13 +1266,27 @@ def test_rstrip
12521266
'hello ', :rstrip
12531267
assert_send_type '() -> String',
12541268
'hello', :rstrip
1269+
1270+
if_ruby("4.0"...) do
1271+
with_string "0-9" do |selector|
1272+
assert_send_type '(String::selector) -> String',
1273+
"01234abc56789", :rstrip, selector
1274+
end
1275+
end
12551276
end
12561277

12571278
def test_rstrip!
12581279
assert_send_type '() -> String',
12591280
+'hello ', :rstrip!
12601281
assert_send_type '() -> nil',
12611282
+'hello', :rstrip!
1283+
1284+
if_ruby("4.0"...) do
1285+
with_string "0-9" do |selector|
1286+
assert_send_type '(String::selector) -> String',
1287+
"01234abc56789", :rstrip!, selector
1288+
end
1289+
end
12621290
end
12631291

12641292
def test_scan
@@ -1491,13 +1519,27 @@ def test_strip
14911519
' hello ', :strip
14921520
assert_send_type '() -> String',
14931521
'hello', :strip
1522+
1523+
if_ruby("4.0"...) do
1524+
with_string "0-9" do |selector|
1525+
assert_send_type '(String::selector) -> String',
1526+
"01234abc56789", :strip, selector
1527+
end
1528+
end
14941529
end
14951530

14961531
def test_strip!
14971532
assert_send_type '() -> String',
14981533
' hello ', :strip!
14991534
assert_send_type '() -> nil',
15001535
'hello', :strip!
1536+
1537+
if_ruby("4.0"...) do
1538+
with_string "0-9" do |selector|
1539+
assert_send_type '(String::selector) -> String',
1540+
"01234abc56789", :strip!, selector
1541+
end
1542+
end
15011543
end
15021544

15031545
def test_sub

0 commit comments

Comments
 (0)