Skip to content

Instantly share code, notes, and snippets.

Created April 11, 2016 18:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/6bf24fd0e8536dc0935c8feba8c4461c to your computer and use it in GitHub Desktop.
Save anonymous/6bf24fd0e8536dc0935c8feba8c4461c to your computer and use it in GitHub Desktop.
class Array
def chunk
ret = []
current = nil
current_a = []
self.each do |x|
if x != current
ret.push current_a
current = x
current_a = []
end
current_a.push x
end
ret.slice! 0 #A little bug in the logic makes this necessary
ret
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment