Skip to content

Instantly share code, notes, and snippets.

@aemadrid
Created July 10, 2018 16:58
Show Gist options
  • Save aemadrid/460c5cc5a825a7d382c86a2cf01ce09e to your computer and use it in GitHub Desktop.
Save aemadrid/460c5cc5a825a7d382c86a2cf01ce09e to your computer and use it in GitHub Desktop.
class MyIO
def initialize(filename)
fd = IO.sysopen(filename)
@io = IO.new(fd)
@buffer = ""
end
def each(&block)
@buffer << @io.sysread(512) until @buffer.include?($/)
line, @buffer = @buffer.split($/, 2)
block.call(line)
each(&block)
rescue EOFError
@io.close
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment