Blocks Are Closures
Where you find there is more to blocks than meets the eye and you learn how to smuggle variables across scopes.
As Bill notes on a piece of scratch paper, a block is not just a floating piece of code. You can’t run code in a vacuum. When code runs, it needs an environment: local variables, instance variables, self….
Because these entities are basically names bound to objects, you can call them the bindings for short. The main point about blocks is that they are all inclusive and come ready to run. They contain both the code and a set of bindings.
You’re probably wondering where the block picks up its bindings. When you ...
Get Metaprogramming Ruby 2 now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.