Skip to content

Instantly share code, notes, and snippets.

@elia
Forked from ggrossetie/read_proc.rb
Created April 17, 2016 20:23
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 elia/ed66eeac3930a4000666def4efd9e71d to your computer and use it in GitHub Desktop.
Save elia/ed66eeac3930a4000666def4efd9e71d to your computer and use it in GitHub Desktop.
class IO
def read
if @eof
''
else
`res = self.read_proc(@path)`
@eof = true
@lineno = res.size
res
end
end
end
FILE_READER = IO.new
def file_read(path)
File.read(@path)
end
FILE_READER.read_proc = file_read
FILE_READER.extend(IO::Readable)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment