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 hard way :(

I find Blocks and Ruby Core chapters hard to understand.

http://teamtreehouse.com/library/programming/ruby-foundations

any tip!

6 Answers

Jason Seifer
STAFF
Jason Seifer
Treehouse Guest Teacher

Hey Ajinkya Borade, great question about blocks. It's difficult to figure out when you should use blocks in your programs. A good example of that is writing a benchmarking method. You'll always want to know when a piece of code starts and when it finishes. By writing the method to take a block, you can check the start and end time before and after the block runs which will be used to compute it. Then you call "yield" inside that method and the block will run. This way, you only need to write that code once. Did that help clear things up at all? I can come up with a better example if not :)

Jason Seifer
STAFF
Jason Seifer
Treehouse Guest Teacher

Hey Ajinkya Borade

What are you having trouble with? I can try and answer specific questions if you have any.

Jason Seifer great to see u on forum :D ^_^

1). I'm through with quiz of Ruby till Ruby Core. I understood what is BLOCKS. But I'm just bit confused why and when you should use them.

Why you should use 'yield', proc and lambda. I'm sorry, I'm from JavaScript background.

2) In Ruby Core chapter, now im clear. I was reading it again n again - the e.g. code.

Jason Seifer Thanks for reply.

In the benchmark chapter you are using blocks to display strings and symbols.

How do I get blocks benchmark? Please guide me on creating benchmark for blocks.

Jason Seifer
STAFF
Jason Seifer
Treehouse Guest Teacher

Sorry Ajinkya Borade I'm not sure I understand what you mean. Are you able to follow along with the videos?

Jason Seifer can u post an example on when we should use yield and proc, lambda. Or a benchmark example of them.