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

Version Path
opal-0.4.3 corelib/opal/enumerator.rb
opal-0.4.2 opal/opal/enumerator.rb
opal-0.4.1 opal/opal/enumerator.rb
opal-0.4.0 opal/opal/enumerator.rb
opal-0.3.44 opal/opal/enumerator.rb
opal-0.3.43 opal/opal/enumerator.rb
opal-0.3.42 opal/opal/enumerator.rb
opal-0.3.41 opal/opal/enumerator.rb
opal-0.3.40 lib/assets/javascripts/opal/enumerator.rb