Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby Ruby Foundations Procs & Lambdas Working With Procs & Lambdas

Why does output from "return_from_labmda" method return the last line of the method?

As expected, the "return_from_proc" method returned the proc contents after called with "variable.call". I expected a similar result with "return_from_lambda", but it returned the last line of the method.

It seems as though the lambda version of the method "returns from the method" rather than "from the lambda" as said in the video. Thoughts?

1 Answer

Luke Buśk
Luke Buśk
21,598 Points

Proc instantly returns from the block and breaks any further operation inside method, Lambda on the other hand returns from block and goes back to the caller (so returns back to the method). Method's always return the last line of code.

Simple as that, huh? Thanks for the clarification!

I guess lambdas would be good as 'remote code' that is incorporated in a number of different methods. Procs, on the other hand, seem like they would be interesting as a method of flow control...

Luke Buśk
Luke Buśk
21,598 Points

Im not experienced enough yet but i believe Proc's are too risky to use and lambda is usually a better choice.