November 2013
Intermediate to advanced
360 pages
9h 7m
English
Blocks are Ruby’s implementation of closures.
Blocks are one of the most commonly used and powerful features of Ruby because they allow you to pass a code snippet to Enumerable methods, such as each, detect, or inject. Using the yield keyword, you can also write your own custom iterators or functions that call blocks for other reasons. Ruby code containing blocks is often more succinct, elegant, and expressive than equivalent code in older languages, such as C.
But don’t jump to the conclusion that blocks are a new idea! In fact, blocks are not new to Ruby at all. The computer science concept ...
Read now
Unlock full access