Blocks, Procs, and Lambdas
Some of the most powerful features of the Ruby language are closures, which are known as blocks, procs, and lambdas within Ruby. Closures within Ruby are also often misunderstood, mainly due to the flexibility when using them within Ruby.
A closure is in essence a function that can be stored as a variable; closures within Ruby are mainly used for iterating through data/result sets. Closures allow external access to local variables from within the closure.
The simplest of the three closures is a block; this follows Ruby’s “normal” programming style. Blocks are simply “bits” of code that can be executed. ...