Why is Proc in ruby return before executing remaining codes in a method from which Proc was called?
def hello
a = Proc.new{ return }
a.call
puts "Hello"
end
def proc
hello
puts "Proc"
end
Here return will skip puts "Hello" and prints only puts "Proc"
But lambda prints puts "Hello" as well.
What's the reason for this?
def find_even; [1, 2, 3].each {|elem| return elem if elem.even? }; end. So, if that's the case, use block/proc. if you want the opposite, use lambda.lambdain the code.