Ruby - Blocks, Procs, and Lambdas
What will be the output of this Ruby code?
def example
p = Proc.new { return 5 }
p.call
return 10
end
puts exampledef example
p = Proc.new { return 5 }
p.call
return 10
end
puts examplereturn inside the Proc causes the entire method to return immediately with 5.return 10 after p.call is never executed because the Proc's return exits the method.15+ quiz questions · All difficulty levels · Free
Free Signup - Practice All Questions