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/andyhite Jul 13 '12
How about this, as a (somewhat contrived) example of using blocks:
A little silly, and probably not the best way to do it, but it's at least another use of blocks to wrap your head around!