Blocks, Procs, and Lambdas

Learning to Yield

Why do some methods accept a block and others don't? It's because methods that accept blocks have a way of transferring control from the calling method to the block and back again. We can build this into the methods we define by using the yield keyword.


Check out the code in the editor. We've set up a series of puts statements so you can see when we're in the block_test method and when we're in the block passed to it. Click Run to see the result!

Community Forums
Get help and ask questions in the Codecademy Forums
Report a Bug
If you see a bug or any other issue with this page, please report it here.