Jump to ratings and reviews
Rate this book

Mastering Ruby Closures: A Guide to Blocks, Procs, and Lambdas

Rate this book
The road to Ruby mastery is paved with blocks, procs, and lambdas. To be a truly effective Ruby programmer, it's not enough just to understand these features - you need to know how to use them in practice. Discover how to write code that is elegant, expressive, and a joy to use, and gain a deep understanding of these concepts so you can work with third-party gems and libraries more easily. Whether you are completely new to Ruby or a seasoned Rubyist, you'll find good use for these concepts in your code.

Ruby developers use the Ruby language as the yardstick for expressivity, flexibility, and elegance - and a large part of this is due to blocks, lambdas, and procs. These language features make Ruby one of the most beautiful and pleasant languages to work with. Learn how to understand and craft code that will take you closer to Ruby mastery.

Start with the basics of closures and then dive into blocks, as you learn about the patterns that involve blocks, and how they are used in real-world code. Then create and use procs and lambdas. Finally, build your own lazy enumerables with advanced Ruby features such as fibers and generators. Along the way, work with computer science concepts such as closures, free variables and first-class functions. Spot a closure easily. Identify the patterns where you can effectively use blocks and re-implement common standard library methods using them. Trace through how Symbol#to_proc works and find out the different ways of calling procs. This succinct guide takes you through the different kinds of Ruby closures with engaging examples, and each chapter comes with exercises that test and challenge your understanding.

When you finish this book, blocks, procs, and lambdas will have become an integral part of your Ruby toolbox.

What You Need: Ruby 2.x and a basic familiarity with Ruby.

96 pages, ebook

First published August 15, 2017

2 people are currently reading
32 people want to read

About the author

Benjamin Tan Wei Hao

3 books11 followers
Benjamin is a Software Engineer at Pivotal Labs, Singapore.

He is the author of The Little Elixir and OTP Guidebook (Manning Publications) and The Ruby Closures Book (The Pragmatic Bookshelf).

Deathly afraid of being irrelevant, is always trying to catch up on his ever-growing reading list.

Ratings & Reviews

What do you think?
Rate this book

Friends & Following

Create a free account to discover what your friends think of this book!

Community Reviews

5 stars
8 (29%)
4 stars
16 (59%)
3 stars
3 (11%)
2 stars
0 (0%)
1 star
0 (0%)
Displaying 1 - 2 of 2 reviews
Profile Image for Gábor L. Hajba.
140 reviews3 followers
December 1, 2017
Disclaimer: I was one of the technical reviewers of this book - but my opinion on it is mine and has nothing to do with this fact. I wasn't paid for my review.

I found the book very interesting. Despite some grammar mistakes while proofreading, this book was great and I feel like the author: I have never used closures in Ruby before but I think I will if the need arises. And I will use closures better because this book has everything to get you from Zero to Hero!
Profile Image for Peter Rybarczyk.
95 reviews10 followers
May 14, 2019
This book will not be a game changer in ma developer career but it's more than worth of reading.
It describes both ruby procs/blocks/lambdas and functional (ruby) closures very well, and as a bonus, it gives you a lot of hints and tips about how Ruby and its basic parts of metaprogramming work.

Strong 4/5
Displaying 1 - 2 of 2 reviews

Can't find what you're looking for?

Get help and learn more about the design.