Sha256: 3a541e555424daf5226bff628f592de6d70a5724ffe26f0fdc5390aa46b1cf0f

Contents?: true

Size: 624 Bytes

Versions: 10

Compression:

Stored size: 624 Bytes

Contents

# DEPRECATE. THIS IS INCLUDED IN ENUMERABLE NOW.
class Array
  # Iterates over +n+ elements at a time. If +n+ is
  # not given then the arity of the block determines the 
  # slicing quantity.
  #
  #   require 'facet/array/each_slice'
  #
  #   [1, 2, 3, 4].each_slice(2){ |a,b| ... }
  #
  # Enumerable#each_slice offers the same functionality 
  # but this is a more efficient implementation specifically
  # for the Array.
  def each_slice(n=nil, &yld)
    n = yld.arity.abs unless n
    i=0
    while i < self.length
      yld.call(*self.slice(i,n))
      i+=n
    end
  end
  alias_method( :each_by, :each_slice )
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
facets-0.6.3 lib/facet-dev/array/each_slice.rb
facets-1.4.2 forge/core/array/each_slice.rb
facets-1.4.1 forge/core/array/each_slice.rb
facets-1.4.3 forge/core/array/each_slice.rb
facets-1.4.4 forge/core/array/each_slice.rb
facets-1.4.5 snip/core/array/each_slice.rb
facets-1.8.0 work/core/array/each_slice.rb
facets-1.8.20 work/core/array/each_slice.rb
facets-1.8.49 work/core/array/each_slice.rb
facets-1.8.8 work/core/array/each_slice.rb