r/learnruby • • Jul 13 '12

Trying to understand calling yield

I'm working through DAB's Well-Grounded Rubyist and am trying to figure out if I understand what is going on in an example he uses. Basically he writes a custom .each method using yield, and then uses that method in a custom .map method using yield as well.

To make sure I was understanding everything, I made my own version with different names/example situation and tried to annotate it to explain what was happening. I'm not sure if I got it right or not, and was looking for some feedback if possible.

My program Result

As a note, Ruby is my first programming language. I'm a grad student in Professional Writing and so my background has been HTML and CSS (no php).

1 Upvotes

4 comments sorted by

View all comments

Show parent comment

1

u/vidus Jul 13 '12

Thanks, that does help. Still working on getting to .downto and other methods, but that looks very useful. Hoping to finish up Well-Grounded and move on to Eloquent Ruby in a week or two, so that should give me a bit better foundation too.