proc and lambda in Ruby – Introduction
Today we are going to talk a little bit about the infamous procs and lambdas in Ruby and the differences between them. Well, you may already know that a
proc and a lambda are objects of the same class:
- p, l = proc{}, lambda{}
- p.class
- #=> Proc
- l.class
- #=> Proc
So is
proc an alias for lambda ? The answer is no. The Proc object returned by a call to proc{} has differences from the Proc object that the lambda{} call returns (This is only true for Ruby 1.9, as of Ruby 1.8 the proc and lambda was just aliases. In Ruby 1.8 the Proc object returned by a call to Proc.new was different from lambda).