Skip to content

Instantly share code, notes, and snippets.

@aviflombaum
Created September 29, 2008 02:18
Show Gist options
  • Save aviflombaum/13543 to your computer and use it in GitHub Desktop.
Save aviflombaum/13543 to your computer and use it in GitHub Desktop.
# Will yield sets of size, useful when you have to iterate over large sets
# if you have an array of 50k elements, running .each is slow.
def in_blocks_of(s)
(1..(self.size/s)).each{|i| yield self[((s)*(i-1))...((s)*i)]} and yield self[((self.size/s)*s)...self.size]
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment