Sha256: e815a7941bb72a8ba2bf096554c11e622f9c20ed354a7ac173e056782c1f6f82
Contents?: true
Size: 940 Bytes
Versions: 3
Compression:
Stored size: 940 Bytes
Contents
class Enumerator # Combine with_index and with_object. # # @example # # %w[a b].each.with_iobject([]){|v, i, memo| # memo << [v, i] # } # -> [a, 0], [b, 1] # # %w[a b].each.with_iobject(2, []){|v, i, memo| # memo << [v, i] # } # -> [a, 2], [b, 3] # # @overload with_iobject(*args) # @param [Fixnum,Object] *args pass Fixnum as offset, otherwise as memo_obj # @return Enumerator # # @overload with_iobject(*args) # @yieldparam [Object] (*args) # @yieldparam [Fixnum] idx index # @yieldparam [Object] memo_obj # # @see with_index # @see with_object def with_iobject(*args, &blk) return self.to_enum(:with_iobject, *args) unless blk (offset,), (memo,) = args.partition{|v| Fixnum === v} index = offset || 0 raise ArgumentError, "must provide memo object" unless memo with_object(memo) do |args2, m| blk.call args2, index, m index += 1 end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
tagen-2.0.2 | lib/tagen/core/enumerator.rb |
tagen-2.0.1 | lib/tagen/core/enumerator.rb |
tagen-2.0.0 | lib/tagen/core/enumerator.rb |