Ruby - vs lambda

Introduction does not check that the number of arguments passed to the block matches the number of block parameters.

lambda does.

The behavior of the proc method is different in Ruby 1.8 and 1.9.

In Ruby 1.8, proc is equivalent to lambda-it checks the number of arguments.

In Ruby 1.9, proc is equivalent to does not check the number of arguments:

a ={|x,y,z| x = y*z; puts(x) },5,10,100)        # This is not an error

b = lambda{|x,y,z| x = y*z; puts(x) },5,10,100)        # This is an error

puts('---Block #2---' )
c = proc{|x,y,z| x = y*z; puts(x) },5,10,100)        # This is an error in Ruby 1.8
                          # Not an error in Ruby 1.9

Related Topic