O'Reilly logo

Mastering Ruby Closures by Benjamin Tan Wei Hao

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

Implementing Callbacks in Ruby with Lambdas

At times, closures allow us to write programs that are otherwise very difficult to express or downright nasty to look at. An example of this is callbacks. Imagine that you’re working with a report-generation tool. The programmer before you hacked together something quick and dirty and has since left for greener pastures. Lucky him. Unfortunately for you, the report-generating method has a couple of bugs, causing crashes to occur 5% of the time.

The code is a complete mess and you have no appetite to go near that monstrosity. Instead, you want to know if a report has been successfully generated and send it to your boss right away. However, when things go awry, you want to be notified personally. ...

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