Skip to content

Commit ffae428

Browse files
committed
Support selector for String#strip family.
1 parent f50c270 commit ffae428

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
@@ -3665,7 +3665,7 @@ class String
36653665
# Related: see [Converting to New
36663666
# String](rdoc-ref:String@Converting+to+New+String).
36673667
#
3668-
def lstrip: () -> String
3668+
def lstrip: (*selector) -> String
36693669

36703670
# <!--
36713671
# rdoc-file=string.c
@@ -3678,7 +3678,7 @@ class String
36783678
#
36793679
# Related: see [Modifying](rdoc-ref:String@Modifying).
36803680
#
3681-
def lstrip!: () -> self?
3681+
def lstrip!: (*selector) -> self?
36823682

36833683
# <!--
36843684
# rdoc-file=string.c
@@ -4191,7 +4191,7 @@ class String
41914191
# Related: see [Converting to New
41924192
# String](rdoc-ref:String@Converting+to+New+String).
41934193
#
4194-
def rstrip: () -> String
4194+
def rstrip: (*selector) -> String
41954195

41964196
# <!--
41974197
# rdoc-file=string.c
@@ -4204,7 +4204,7 @@ class String
42044204
#
42054205
# Related: see [Modifying](rdoc-ref:String@Modifying).
42064206
#
4207-
def rstrip!: () -> self?
4207+
def rstrip!: (*selector) -> self?
42084208

42094209
# <!--
42104210
# rdoc-file=string.c
@@ -4677,7 +4677,7 @@ class String
46774677
# Related: see [Converting to New
46784678
# String](rdoc-ref:String@Converting+to+New+String).
46794679
#
4680-
def strip: () -> String
4680+
def strip: (*selector) -> String
46814681

46824682
# <!--
46834683
# rdoc-file=string.c
@@ -4690,7 +4690,7 @@ class String
46904690
#
46914691
# Related: see [Modifying](rdoc-ref:String@Modifying).
46924692
#
4693-
def strip!: () -> self?
4693+
def strip!: (*selector) -> self?
46944694

46954695
# <!--
46964696
# 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)