Commit c2504837

c250483716ceMerged

Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 2 files · ~2 modified

Description

Array#grep / #grep_v without a block

Filter an array by pattern === element for Range, Class, and Regexp patterns, preserving the receiver's array type. grep_v negates the test.

Co-Authored-By: Claude Opus 4.8 [email protected]

Details

Commit
c250483716ce
Parent
8510a9e19b2a

src/analyze.cmodifiedView file

@@ -514,6 +514,11 @@
514514 !strcmp(name, "find") || !strcmp(name, "detect"))
515515 return ty_array_elem(rt); /* returns an element */
516516 }
517+ /* grep/grep_v without a block filter by `pattern === e`, preserving the
518+ receiver's array type. */
519+ if ((!strcmp(name, "grep") || !strcmp(name, "grep_v")) &&
520+ nt_ref(nt, id, "block") < 0 && argc == 1)
521+ return rt;
517522 if (!strcmp(name, "[]")) {
518523 /* arr[range] / arr[start, len] -> a subarray; arr[i] -> an element */
519524 if (argc == 2) return rt;