Chapter 1Closing in on Closures

Chances are you’ve heard about closures and tried to find out what they’re all about. You clicked on the first link, which led you to an utterly incomprehensible Wikipedia entry. Your eyes glazed over terms like lexical scoping and free variables, and you started to think maybe you’re just not that smart. If you are in that situation, here’s some great news. This is totally learnable. You just need to learn a few rules and some new terminology.

In this chapter, you’ll learn the rules that define a closure, so you can identify one when you see it. Knowing these rules will also help you understand the more advanced concepts in the rest of the book. Furthermore, you can transfer these concepts to other languages ...

Get Mastering Ruby Closures 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.