Wrapping Up

Procs and lambdas are powerful tools to have in your Ruby arsenal. Their purpose is simple: to allow pieces of code to be carried around. However, the consequences are far-reaching.

Developers have been using functional programming techniques in Ruby code to great effect. It’s hard to imagine idiomatic Ruby code without functions like map and reduce. However, in order to write idiomatic code using Procs and lambdas, it’s important to understand its usages and nuances.

In a beautifully meta sort of way, Procs and lambdas have been exploited to enhance the Ruby language itself, with Symbol#to_proc as a shining example. Now that you’ve gone through the implementation of Symbol#to_proc, hopefully you realize that there is absolutely ...

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.