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 trialabhishek pareek
Courses Plus Student 3,905 PointsPassing a block as a parameter to a function while using yield?
I see that Jason is passing a block
as a parameter to a function in the latter half of the video.
However I don't know if that is useful as the block itself isn't being explicitly called here ala block.call
. So the parameter being passed is redundant and not being used.
Opinions?
1 Answer
Jack Choi
11,420 PointsYou're correct in that it's certainly not necessary to explicitly have &block as a parameter in this case. I'm not entirely sure either but one reason I can think of is for readability (or self-documenting code). Without the block parameter in the function signature one wouldn't know it takes a block with a quick glance. Of course, you can always go through the function and see that there's a yield somewhere in the function.