lib/backports/2.0.0/enumerator/lazy.rb in backports-2.8.1 vs lib/backports/2.0.0/enumerator/lazy.rb in backports-2.8.2

- old
+ new

@@ -7,11 +7,11 @@ # or http://bugs.ruby-lang.org/issues/7696 attr_accessor :backports_memo end class Lazy < Enumerator - @@done = Object.new # used internally to bail out of an iteration + @@done = :__backports_lazy_enumeration_done__ # used internally to bail out of an iteration alias_method :non_lazy_cycle, :cycle # cycle must be handled in a tricky way @@cycler = Struct.new(:object, :n) def initialize(obj) @@ -73,11 +73,11 @@ end def drop(n) n = Backports::coerce_to_int(n) Lazy.new(self) do |yielder, *values| - data = yielder.backports_memo ||= {remain: n} + data = yielder.backports_memo ||= {:remain => n} if data[:remain] > 0 data[:remain] -= 1 else yielder.yield(*values) end @@ -85,21 +85,21 @@ end def drop_while raise ArgumentError, "tried to call lazy drop_while without a block" unless block_given? Lazy.new(self) do |yielder, *values| - data = yielder.backports_memo ||= {dropping: true} + data = yielder.backports_memo ||= {:dropping => true} yielder.yield(*values) unless data[:dropping] &&= yield(*values) end end def take(n) n = Backports::coerce_to_int(n) raise ArgumentError, 'attempt to take negative size' if n < 0 return Lazy.new([]){} if n == 0 Lazy.new(self) do |yielder, *values| - data = yielder.backports_memo ||= {remain: n} + data = yielder.backports_memo ||= {:remain => n} yielder.yield(*values) throw @@done if (data[:remain] -= 1) == 0 end end @@ -135,10 +135,10 @@ arys = args.map{ |arg| Backports.is_array?(arg) } if arys.all? # Handle trivial case of multiple array arguments separately # by avoiding Enumerator#next for efficiency & compatibility Lazy.new(self) do |yielder, *values| - data = yielder.backports_memo ||= {iter: 0} + data = yielder.backports_memo ||= {:iter => 0} values = values.first unless values.size > 1 yielder << arys.map{|ary| ary[data[:iter]]}.unshift(values) data[:iter] += 1 end else