4 ms·
I think the crucial difference is that a block can control the flow of the enclosing frame, somewhat analogously to python context managers. For example def
by hnov 5y ago
I think the crucial difference is that a block can control the flow of the enclosing frame, somewhat analogously to python context managers. For example
def get_widget
with_lock do
return @widget # returns from the method call
end
end
def update_interesting_gadget
@gadgets.each do |g|
g.with_lock do
if g.is_theone?
g.update
break # breaks the enclosing each's while loop
end
end
end
- joelbluminator 5y agoSo Anonymous Ruby blocks act like (or are) Procs (which return from the parent method), not like lambdas, would you say that?