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 Foundations Blocks Yield

PAUL JULIAN
PAUL JULIAN
16,038 Points

BLOCK NAME

Just to confirm, the block has to have the same name as the method that's calling it?

4 Answers

Jamie Barton
Jamie Barton
14,498 Points

PAUL JULIAN From what I can gather yes, otherwise you don't know the method you're sending a block to.

Jamie Barton
Jamie Barton
14,498 Points

Hi PAUL JULIAN

You can pass in anything to the block which is a local variable. So in that video show_numbers do |number| could be |n| or |num|

You can also use names inside of the setter and getter blocks which don't have to be the same.

Is this what you mean?

PAUL JULIAN
PAUL JULIAN
16,038 Points

I mean 'show_numbers' do |number| ... has to be the same as the method name 'def show_numbers'