One not documented behavior im lambda

proc { |…| block } => a_proc, lambda { |…| block } => a_procEquivalent to Proc.new, except the resulting Proc objects check the number of parameters passed when called.
Ruby official doc

But at least are one more difference :

def foo
  f = Proc.new { return "return from foo from inside proc" }

  f.call # control leaves foo here

  return "return from foo"

end

def bar

  f = lambda { return "return from lambda" }

  f.call # control does not leave bar here

  return "return from bar"

end

puts foo # prints "return from foo from inside proc"

puts bar # prints "return from bar"

Wikipedia

2 comments so far

  1. name on

    Good day!,

  2. name on

    Hello!,


Leave a comment