Module 23 Β· Design Patterns (All 23 GoF) β Lesson 16 of 23 Β· ~6 min
Iterator
Iterator: step through a collection without exposing internals
Problem: callers want to walk your collection in order without knowing whether it's an array, a tree, or a linked list inside.
Say it plainly: in Ruby this is nearly built in. Define
each,include Enumerable, and you getmap,select,sort,to_a, and dozens more for free.
PawWalk scenario: iterate a booking calendar in order β callers just call .each or .map and never see the storage.