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 Blocks: modify the yield statement to send the monster instance to a block...

I hope I am not the only one who is completely confused by the last code challenge in the Ruby blocks section. I thought I understood what I had to do but nothing seems to work.

Here's what Treehouse asks us to do: "In the scream method, modify the yield statement to send the monster instance to a block if a block is sent in to the scream method."

I've added 'monster' and even 'Monster.new("Fluffy") after the 'yield' keyword. One would think this is what's meant by "the monster instance."

Any suggestions?

Thanks.

2 Answers

You're sorta on the right track.

if you were to add Monster.new after yield, you'd be sending a brand new, untouched, unnamed (probably wouldn't work) to the block.

Instead, you're asked to send the current Monster instance to a block if a block is sent to the scream method. In this case you'd use the self keyword along with the block_given? method that Jason shows in the previous video.

yield self if block_given?

Thanks Ricardo. I appreciate the help. I'll have to rewatch that portion of the video.

No problem. I just finished that course earlier today, and it certainly was not easy.