Welcome to the Treehouse Community
Looking to learn something new?
Aimee Knight9,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?
Jason SeiferTreehouse 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: