Commit 5aa336d6
5aa336d6ea70Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 8 months ago · 2 files · +1 added · ~1 modified
Description
Add Array#count (with/without block), min_by, max_by, sort_by for IntArray; count (with/without block) for StrArray
Block params in StrArray blocks are now properly typed as STRING for type inference, enabling chained method calls like w.length > 3.
Co-Authored-By: Claude Opus 4.6 (1M context) [email protected]
Details
- Commit
- 5aa336d6ea70
- Parent
- 2b3a6d2417a3
examples/bm_array3.rbaddedView file
1+
# Test additional array methods2+
3+
arr = Array.new4+
arr.push(5); arr.push(3); arr.push(8); arr.push(1)5+
arr.push(4); arr.push(2); arr.push(7); arr.push(6)6+
7+
# count with block8+
puts arr.count { |x| x > 4 } # 4 (5,8,7,6)9+
10+
# count without block11+
puts arr.count # 812+
13+
# min_by / max_by14+
puts arr.min_by { |x| x } # 115+
puts arr.max_by { |x| x } # 816+
17+
# sort_by18+
sorted = arr.sort_by { |x| -x }19+
puts sorted[0] # 820+
puts sorted[1] # 721+
puts sorted[7] # 122+
23+
# StrArray count24+
words = "hello world foo bar".split(" ")25+
puts words.count { |w| w.length > 3 } # 2 (hello, world)26+
puts words.count # 427+
28+
puts "done"src/codegen.cmodifiedView file
Loading diff…