What Is the Difference Between a Block, a Proc, and a Lambda in Ruby? (2013)

4 Tomte 1 5/18/2025, 6:34:12 PM blog.awaxman.com ↗

Comments (1)

vidarh · 37m ago
Separating out blocks this way is pretty meaningless. Blocks are a syntactical construct that can be optimized a certain way, and is in MRI.

You can obtain a value of a block by naming it, and when you do, what you obtain is a proc.

A Ruby implementation could if it chooses make any block a proc, because you shouldn't be able to tell the difference without extensive contortions (e.g. you could iterate over ObjectSpace and show that a block causes the creation - or not - of an object of the Proc class). And in-fact my (woefully buggy and incomplete) Ruby compiler prototype does just that.