Life Without Iterators
Let's play dumb for a while: Suppose we've never seen iterators, and we would like to give an object foo a completely new task to do. We mean this in a very general sense; although the object has its own methods, which are the tricks it already knows how to perform, we'd like to be able to tell it to do something arbitrary and unfamiliar. In other words, we'd like to pass it some code. How can we teach an old dog a new trick?
Here's a little game to make the problem a little more concrete. Secretive is a class whose objects each own a number @r chosen randomly somewhere between 0 and 1.
Note
That's strictly less than 1, although possibly equal to 0. (It will probably take you a lot of tries before you see it come out to ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access