Commit 7143f34b
7143f34b83beMerged
Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 2 files · ~2 modified
Description
String#gsub/sub with a block
Iterate the matches of a regex literal, binding the block parameter to each matched substring and appending the block's return value as the replacement. sub replaces only the first match; gsub walks the whole string and advances past zero-width matches. analyze types the block parameter as a string. Backref expansion does not run on block returns, matching Ruby.
Co-Authored-By: Claude Opus 4.8 [email protected]
Details
- Commit
- 7143f34b83be
- Parent
- d3dba14a2d70
src/analyze.cmodifiedView file
@@ -1980,6 +1980,8 @@
19801980
pt = TY_INT;19811981
else if (rt == TY_STRING && (!strcmp(name, "each_char") || !strcmp(name, "each_line") || !strcmp(name, "upto")))19821982
pt = TY_STRING;1983+
else if (rt == TY_STRING && (!strcmp(name, "gsub") || !strcmp(name, "sub")))1984+
pt = TY_STRING; /* block receives the matched substring */19831985
else if (rt == TY_STRING && !strcmp(name, "each_byte"))19841986
pt = TY_INT;19851987
else if ((!strcmp(name, "each") || !strcmp(name, "map") || !strcmp(name, "collect") ||src/codegen.cmodifiedView file
Loading diff…