Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.


Aimee Knight
Aimee Knight
9,701 Points

Ruby - calling blocks via yield

I noticed in the Ruby videos that Jason tends to prepend method arguments with the ampersand when calling the block via call and yield. However, with some of the simple examples I've run, the method runs with yield when omitting the prepended ampersand in the method arguments. (Initially I read that performance wise it's best to use yield without the prepended ampersand argument.) I see Jason using the prepended ampersand argument while also using yield so, are there other difference between the two approaches that influence Jason's preference in the videos?

2 Answers

Jason Seifer
Jason Seifer
Treehouse Guest Teacher

The ampersand explicitly assigns the block to a variable inside of the method. In a lot of circumstances it's a preference thing but there are also times where the behavior is really necessary. For an in depth explanation, check out this article: