I don't think the close_io stuff is necessary in this implementation since yielding the file from the File.open block should handle closing open files. And you may not want to close the stream if it is an already open stream.