Proc.new vs Lambda in Ruby

Posted by piemesons on Stack Overflow See other posts from Stack Overflow or by piemesons
Published on 2010-05-27T10:16:02Z Indexed on 2010/05/27 10:21 UTC
Read the original article Hit count: 232

Filed under:

Plese check this:

 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" 

Can anybody tell me what lambda is and what is Proc and whats the difference.

© Stack Overflow or respective owner

Related posts about ruby