Skip to content

Instantly share code, notes, and snippets.

@bunnymatic
Created November 10, 2012 08:03
Show Gist options
  • Save bunnymatic/4050373 to your computer and use it in GitHub Desktop.
Save bunnymatic/4050373 to your computer and use it in GitHub Desktop.
chunk a string into equal length parts
class String
def chunk(ct)
result = []
dup = self.dup
val = dup.slice!(0..(ct-1))
until val.empty? || !val do
result << val
val = dup.slice!(0..(ct-1))
end
result
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment