I've been playing with the Codecademy Ruby course and there's an exercise on lambdas and Procs. I do understand the difference, but I don't quite see why the first code listing here works, while the second does not.
Why does this work:
def batman_ironman_proc
p = Proc.new { return "Batman will win!" }
p.call
"Iron Man will win!"
end
puts batman_ironman_proc # prints "Batman will win!"
But not this:
def batman_ironman_proc(p)
p.call
"Iron Man will win!"
end
p = Proc.new { return "Batman will win!" }
puts batman_ironman_proc(p) # unexpected return