Created
September 22, 2009 19:08
-
-
Save adhusson/191327 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Array | |
def each_slice_with_index(slice_size) | |
nb_slices = (self.size.to_f/slice_size).ceil | |
for i in 0...nb_slices | |
yield self[i*slice_size,slice_size], i | |
end | |
end | |
def each_slice_with_index_alt(slice_size) | |
slices = self.enum_slice(slice_size).map | |
slices.each_with_index { |slice,index| | |
yield slice,index | |
} | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment