Last active
December 14, 2015 01:39
-
-
Save kchau/5008255 to your computer and use it in GitHub Desktop.
#chunk_lines sample
This file contains hidden or 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
# 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