3 ms·
The author overlooked the most mind-bending feature of Ruby blocks, the thing that makes them so very different than lambdas in other languages: Blocks can retu
by mdavidn 5y ago
The author overlooked the most mind-bending feature of Ruby blocks, the thing that makes them so very different than lambdas in other languages: Blocks can return from the enclosing function.
def process
collection.each do |element|
return element if condition
end
end
This has the effect of popping three (or more) frames off the stack. From the perspective of #each, yield never returns.