A friend of mine asked me to describe the differences among blocks, procs and lambdas in Ruby. I had to admit that I didn’t really know!
One of the niceties of Ruby is the expressiveness of the language. It can be shaped and molded, stretched and teased in all sorts of ways that other languages just can’t. I attribute most of this to the presence of closures.
Given the amount of time I spend working in other languages, I guess I have gotten used to doing what can be done with closures in other, less elegant ways.
I've got a masters degree in computer science and over 10 years of experience building web-based systems using Java/J2EE, Ruby, Rails and PHP. I'm a strong believer in the effectiveness of Agile Methods. Read more »
Ruby Blocks, Procs, Lambda
A friend of mine asked me to describe the differences among blocks, procs and lambdas in Ruby. I had to admit that I didn’t really know!
One of the niceties of Ruby is the expressiveness of the language. It can be shaped and molded, stretched and teased in all sorts of ways that other languages just can’t. I attribute most of this to the presence of closures.
Given the amount of time I spend working in other languages, I guess I have gotten used to doing what can be done with closures in other, less elegant ways.
After being stumped by such a fundamental question I did a little digging and found a wonderful explanation of the differences among blocks, procs and lambdas by Robert Sosinksi. This guy really knows his Ruby.
Now I have a good grasp over the various types of closures in Ruby and look forward to putting them to good use.
Thanks for taking the time to write that up Robert!