ruby-marc/ruby-marc — pull request #14 by billdueber (2013-07-26 20:57:32+00:00)
Title: Change readers #each implementations to allow creation of iterators

by calling Enumerable methods (#each, #each_with_index, etc.)
without a block. Makes it easier to do things like only pull off the first N results, etc. Done mostly to conform with the way Ruby 1.9 treats its standard enumerable classes

Tests included for xml and binary readers, verified under MRI and JRuby

Example:

reader.each {|r| puts r} # normal
iter = reader.each_with_index # get an enumerator/iterator/whatever

iter.next #=> [, 0]
begin
while pair = iter.next
r = pair.shift
index = pair.shift
puts r
end
rescue StopIteration
puts "All done!"
end