Sha256: e64d12c190e483567a38cdbc2c597414706b3ece8263d236ae75bcd312e50caf

Contents?: true

Size: 727 Bytes

Versions: 16

Compression:

Stored size: 727 Bytes

Contents

require 'facets/enumerator'

module Enumerable

  # Iterate through slices. If slice +steps+ is not
  # given, the arity of the block is used.
  #
  #   x = []
  #   [1,2,3,4].each_by{ |a,b| x << [a,b] }
  #   x  #=> [ [1,2], [3,4] ]
  #
  #   x = []
  #   [1,2,3,4,5,6].each_by(3){ |a| x << a }
  #   x  #=> [ [1,2,3], [4,5,6] ]
  #
  # This is just like each_slice, except that it will check
  # the arity of the block. If each_slice ever suppots this
  # this method can be deprecated.
  #
  # CREDIT: Trans

  def each_by(steps=nil, &block)
    if steps
      each_slice(steps, &block)
    else
      steps = block.arity.abs
      each_slice(steps, &block)
      #each_slice(steps) {|i| block.call(*i)}
    end
  end

end

Version data entries

16 entries across 15 versions & 2 rubygems

Version Path
facets-glimmer-3.2.0 lib/core/facets/enumerable/each_by.rb
facets-3.1.0 lib/core/facets/enumerable/each_by.rb
facets-3.0.0 lib/core/facets/enumerable/each_by.rb
facets-2.9.3 lib/core/facets/enumerable/each_by.rb
facets-2.9.2 lib/core/facets/enumerable/each_by.rb
facets-2.9.2 src/core/facets/enumerable/each_by.rb
facets-2.9.1 lib/core/facets/enumerable/each_by.rb
facets-2.9.0 lib/core/facets/enumerable/each_by.rb
facets-2.9.0.pre.2 lib/core/facets/enumerable/each_by.rb
facets-2.9.0.pre.1 lib/core/facets/enumerable/each_by.rb
facets-2.8.4 lib/core/facets/enumerable/each_by.rb
facets-2.8.3 lib/core/facets/enumerable/each_by.rb
facets-2.8.2 lib/core/facets/enumerable/each_by.rb
facets-2.8.1 lib/core/facets/enumerable/each_by.rb
facets-2.8.0 lib/core/facets/enumerable/each_by.rb
facets-2.7.0 lib/core/facets/enumerable/each_by.rb