Flowdock

Notes posted by x2es

RSS feed
October 6, 2011
1 thank

Difference in the way returns are handled

Also, there is a difference in the way returns are handled from the Proc. A return from Proc.new returns from the enclosing method. Return in lambda-block acts like in regular method.

return example

def proc_return
  Proc.new { return "Proc.new"}.call
  return "proc_return method finished"
end

def lambda_return
  lambda { return "lambda" }.call
  return "lambda_return method finished"
end
puts proc_return
puts lambda_return
# => Proc.new
# => lambda_return method finished