Code blocks and other members of the closure family are something near to many Rubyists’ hearts. They are extremely powerful, flexible, and, when used well, elegant. They are the cornerstones of Ruby’s functional style of programming.

In this series, we will take a look at procs, code blocks, lambdas, and closures in Ruby and explore the differences between them and how to use them.

I was afraid of all these names for a long time. But after taking a really close look at each one of them and their relationships to each other, I realized they were not that scary at all. Instead, I promise you, they are really fun subjects.

This is part 1 of a three-part series.

Part 1 covers the following four fundamentals:

Definitions of Code Block, Proc, Lambda, and Closure Constructions Calling a Code Block/Proc/Lambda Passing and Returning Procs

Part 2 covers

5. Scopes, Universes, and Lunch Boxes [FUN STUFF]

6. Differences between a Proc and a Lambda

Part 3 covers:

7. Proc <> Code Block Conversion and Ampersand(&) [FUN STUFF]