Module 26 Β· Enumerable, Enumerator & Pattern Matching β Lesson 3 of 6 Β· ~9 min
Enumerators & Lazy Evaluation
A blockless iterator returns an Enumerator
You saw it in module 25: call each (or map, select, β¦) without a block and you get back an Enumerator β an object that has captured "how to iterate" and can be driven later. This is why arr.each.with_index and arr.map.with_index work: the blockless call returns an Enumerator, and with_index chains onto it.
In an interview, say: "Calling an iterator without a block returns an Enumerator β a paused, resumable iteration you can chain (
with_index,with_object) or pull one-at-a-time withnext. It decouples how to iterate from what to do."