O'Reilly logo

Ruby Quick Syntax Reference by Matt Clements

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

CHAPTER 12

image

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.

Blocks

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. ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required