Skip to content

Instantly share code, notes, and snippets.

@kchau
Last active December 14, 2015 01:39
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 kchau/5008255 to your computer and use it in GitHub Desktop.
Save kchau/5008255 to your computer and use it in GitHub Desktop.
#chunk_lines sample
# Break the IO stream into manageable chunks.
# @param [io] io to read input. Usually File based, but can be any Ruby IO.
# @yieldparam [block] the block that the chunk is yielded to.
#
def chunk_lines(io, &block)
chunk= []
io.each_line do |line|
chunk << line.strip
if chunk.size == DEFAULT_SIZE
yield chunk
chunk= []
end
end
yield chunk
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment