Prompted by a recent contribution to fix Ruby 1.9 enumerator compatibility (to be included in RDF.rb 0.1.8), I'm investigating what it will take to ensure that our use of enumerators is safe and compatible with all Ruby baseline versions that we wish to support (that is, 1.8.2+ and 1.9.x).
The Ruby 1.8.x ChangeLog reveals that the enumerator standard library, which provides the Enumerable::Enumerator class, was added to Ruby back in 2003 and first debuted in the MRI 1.8.1 release.
Hence it is always safe to do an unconditional require 'enumerator' without breaking compatibility with any 1.8.2+ release (our current minimum required Ruby version). Therefore in RDF.rb 0.1.8 I have factored out the previously-used conditional inline require statements in favor of a single unconditional one in lib/rdf.rb that is executed when RDF.rb is first loaded up.
Now, Enumerable::Enumerator was renamed to Enumerator in the 1.9.0 release, without leaving a compatibility alias at the old name. So, to avoid having to use an incidental bit of conditional logic at every point where Enumerator objects are instantiated, I've introduced a convenient RDF::Enumerator constant in RDF.rb 0.1.8:
require 'enumerator' # @since Ruby 1.8.1
# For compatibility with both Ruby 1.8.x and Ruby 1.9.x:
Enumerator = defined?(::Enumerator) ? ::Enumerator : ::Enumerable::Enumerator
This means that any code contained within the RDF namespace (including RDF.rb plugins that keep to the recommended naming conventions) can now refer to enumerators using simply the class name Enumerator (as they would on Ruby 1.9+), and anything outside the RDF namespace (e.g. specs) can use the qualified RDF::Enumerator to considerably simplify backwards-compatible enumerator usage.