Ruby's block syntax is essentially a method of passing an anonymous function as an argument to a method call. It is used by the standard libraries iteration method (e.g., Enumerable#each), but its use here is not iteration (though the teller could be implemented with iteration under the covers.)
data_source.person(...) appears to be a method that takes an id, attempts to retrieve the person with the ID, and, if such a person object exists, yields the person object to the block. From the code, it doesn't look like it is designed to be a collection (it could be implemented on top of a finder that returned a collection, or a finder that returned either a record or nil.)
class DataSource
def person(id)
p = find_person(id)
p && yield p
end
endIt's not iterating.
Conceptually, they both say "update this field for every entry having this ID" and at a quick glance the code for each language looks almost the same.
To an extent yes. I'd fully expect the Ruby version to run more code after the block has been executed, the Python version much less so (even though it is possible) for instance.
The author's example code appears to be doing the same thing, but iterating using Ruby's block syntax:
I'm assuming data_source.person(id) would return 0 or more Person objects.