Doug Turnbull breaks down a major difference between two beloved programming languages in how they handle iteration.
for. Objects tell
forhow to work with them, and the for loop’s body processes what’s given back by the object. Ruby does the opposite. In Ruby,
each) is a method of the Object. The caller passes the body of the for loop to this method.
He goes on to give examples and explain why each approach might map to different developers’ brains… differently. Here’s a succinct summary, if you don’t have time for the deeper discussion:
In Ruby, the objects control the affordances. In Python, the language does.