4 ms·
It's true that lexically scoped variables can replace closures when all you're using closures for is to wrap a section of code in starting and ending sections.
by dmnd 17y ago
It's true that lexically scoped variables can replace closures when all you're using closures for is to wrap a section of code in starting and ending sections. But blocks are more general purpose than this. Have a look at the clean API that blocks have enabled in Ruby's Enumerable module, for example. Once you're using blocks/closures, why not use them to acquire/release resources as well?