Sha256: 7f92562ffacec84c5fc4455f1991376e82975078fae23c5ad1a22f3954a1304b
Contents?: true
Size: 461 Bytes
Versions: 9
Compression:
Stored size: 461 Bytes
Contents
class Enumerator include Enumerable def initialize(obj, method = :each, *args) @object = obj @method = method @args = args end def each(&block) return enum_for :each unless block_given? @object.__send__(@method, *@args) do |e| block.call e end end def next @cache ||= to_a raise StopIteration, 'end of enumeration' if @cache.empty? @cache.shift end def rewind @cache = nil self end end
Version data entries
9 entries across 9 versions & 1 rubygems