File tree 2 files changed +7
-1
lines changed
2 files changed +7
-1
lines changed Original file line number Diff line number Diff line change @@ -1001,6 +1001,12 @@ describe "String" do
1001
1001
str.sub(/(he|l|o) / , {" l" => " la" }).should be(str)
1002
1002
end
1003
1003
1004
+ it " subs with regex and named tuple" do
1005
+ str = " hello"
1006
+ str.sub(/(he|l|o) / , {he: " ha" , l: " la" }).should eq(" hallo" )
1007
+ str.sub(/(he|l|o) / , {l: " la" }).should be(str)
1008
+ end
1009
+
1004
1010
it " subs using $~" do
1005
1011
" foo" .sub(/(o) / ) { " x#{ $1 } x" }.should eq(" fxoxo" )
1006
1012
end
Original file line number Diff line number Diff line change @@ -1423,7 +1423,7 @@ class String
1423
1423
# "hello".sub(/(he|l|o)/, {"he": "ha", "l": "la"}) # => "hallo"
1424
1424
# "hello".sub(/(he|l|o)/, {"l": "la"}) # => "hello"
1425
1425
# ```
1426
- def sub (pattern : Regex , hash : Hash (String , _))
1426
+ def sub (pattern : Regex , hash : Hash (String , _) | NamedTuple )
1427
1427
sub(pattern) { |match |
1428
1428
if hash.has_key?(match)
1429
1429
hash[match]
You can’t perform that action at this time.
0 commit comments