I've been reading over the Enumerable module in Ruby, and it contains a few methods that follow the pattern ofenum.foo(n) {|obj| block }  nilenum.foo(n)  an_enumeratorWhich is to say, they seem to return an iterator when chained and nothing otherwise. What's the reasoning behind taking this approach instead of just returning a sequence? (I'm asking about general reasoning for this approach, not necessarily just its use in Ruby)
Enumerators vs. returning
ruby;iterator
I think it was introduced to better support chaining of operations. It can be too expensive to generate unnecessary intermediate objects.See for example https://github.com/rdp/ruby_tutorials_core/wiki/enumerator