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 Creating Blocks

David Forero
David Forero
5,492 Points

I am having trouble understanding the block concept. It's unclear.

I am having trouble understanding the block concept. It's unclear. Not sure how they work. Seems like Jason is jumping between difficulty levels with in this blocks section.

This might help, if you've not already seen it: http://stackoverflow.com/questions/4911353/best-explanation-of-ruby-blocks

Personally, I still don't understand blocks entirely, but it seems to me (and is sometimes explained as) they're essentially anonymous functions. Don't hold me to that, though :P

Good luck with your search for the understanding of Ruby blocks. Maybe Jason Seifer, or another Ruby pro, will stop by and go into more detail.

3 Answers

Maciej Czuchnowski
Maciej Czuchnowski
36,441 Points

You will get used to it once you write a few methods and blocks on your own and experiment a bit. Here you can do some additional free exercises on methods and blocks: http://www.codecademy.com/courses/ruby-beginner-en-ET4bU/0/1?curriculum_id=5059f8619189a5000201fbcb

(you can jump to exercise 9 if you want, but the first 8 are a good refresher)

Struggled with blocks as well, but I found this video incredibly helpful:

https://www.youtube.com/watch?v=K8uhD8mtorE

Little long (30 min video), but solid explanation.

Thanks so much for posting this video. It helped me a lot.

I found the explanations in http://docs.ruby-doc.com/docs/ProgrammingRuby/ (and the newer edition as well) to be really helpful for getting a better understanding of some of the concepts covered in this series - including blocks (in the Containers, Blocks, and Iterators section.)