+ 1

Ruby - Who can explain me why is output 21?

def one ->(){return 1}.call return 2 end def two Proc.new {return 1}.call return 2 end print one,two

4th Jan 2020, 8:14 PM
Paolo De Nictolis
Paolo De Nictolis - avatar
1 Answer
+ 6
When a lambda encounters a return statement it returns execution to the enclosing method. However, when a Proc encounters a return statement it jumps out of itself, as well as the enclosing method. https://www.sololearn.com/learn/Ruby/2780/
4th Jan 2020, 8:26 PM
Kevin â˜