r/learnruby • u/vidus • 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.
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).
View all comments
Show parent comment
1
u/vidus Jul 13 '12
Yes, that does make sense. Thanks for your reply :) I've been slowly working through the book attempting to do what you mentioned--making custom examples using the new tools I've picked up. I'll try to make something tonight that uses the blocks/procs in a bit more novel of a way. My go to thus far has been coming up with different ways of writing a program to sing 99 bottles of x on the wall.