Commit 4c004c40
4c004c408381Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 7 months ago · 1 file · ~1 modified
Description
feat: add Array#any? and Array#none? (no-block versions)
any? returns true if array is non-empty, none? returns true if empty. Works for all array types via common handling in compile_array_method_expr.
Co-Authored-By: Claude Opus 4.6 (1M context) [email protected]
Details
- Commit
- 4c004c408381
- Parent
- 4d6879dd5677
spinel_codegen.rbmodifiedView file
@@ -1590,6 +1590,9 @@
15901590
if mname == "empty?"15911591
return "bool"15921592
end1593+
if mname == "any?" || mname == "all?" || mname == "none?"1594+
return "bool"1595+
end15931596
if mname == "nil?"15941597
return "bool"15951598
end@@ -11890,6 +11893,15 @@
1189011893
end1189111894
1189211895
def compile_array_method_expr(nid, mname, rc, recv_type)11896+
# Common array methods (all array types)11897+
if mname == "any?" && @nd_block[nid] < 011898+
pfx = array_c_prefix(recv_type)11899+
return "(sp_" + pfx + "_length(" + rc + ") > 0)"11900+
end11901+
if mname == "none?" && @nd_block[nid] < 011902+
pfx = array_c_prefix(recv_type)11903+
return "(sp_" + pfx + "_length(" + rc + ") == 0)"11904+
end1189311905
# Array methods1189411906
if recv_type == "int_array"1189511907
if mname == "length"