Commit 0fa8b592
0fa8b5922e38Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 8 months ago · 2 files · +1 added · ~1 modified
Description
Add block_given?, fix block variable capture for writes
- block_given? → (_block != NULL) in yield functions
- Yield function calls without blocks pass NULL, NULL
- Fix scan_captures: writes to outer-scope variables are captures (previously treated as local definitions, breaking the callback)
Category 3 (block completeness) — block_given? done.
Co-Authored-By: Claude Opus 4.6 (1M context) [email protected]
Details
- Commit
- 0fa8b5922e38
- Parent
- 583eeebe16e0
examples/bm_block2.rbaddedView file
1+
# Test block_given? and optional blocks2+
3+
def maybe_yield(x)4+
if block_given?5+
yield x6+
else7+
x * 28+
end9+
end10+
11+
puts maybe_yield(5) # 10 (no block)12+
13+
result = 014+
maybe_yield(5) do |n|15+
result = n * 316+
end17+
puts result # 1518+
19+
# Method that always yields20+
def each_pair(a, b)21+
yield a22+
yield b23+
end24+
25+
total = 026+
each_pair(10, 20) do |n|27+
total += n28+
end29+
puts total # 3030+
31+
puts "done"src/codegen.cmodifiedView file
Loading diff…