According to this rubyquiz, external iterators used to be slow, but are now faster. Is this an improvement only available in YARV (the C-based implementation of ruby 1.9), or is this also available in the C-based implementation of ruby 1.8.7?
Also, does enum_for rely on external iterators?
Ruby 1.9 uses fibers to implement
Enumerator#next, which might be better than Ruby 1.8, but still makes it an expensive call to make.enum_forreturns anEnumeratorbut does not rely on external iterators. A fiber/continuation will be created only if needed, i.e. if you callnextbut not if you calleachor any other method inherited fromEnumerable.Rubinius and JRuby are optimizing
nextfor the builtin types because it is very difficult to implement, in particular on the JVM. Fun bedtime reading: this thread on ruby-core