ahoward (owner)

Revisions

gist: 214696 Download_button fork
public
Public Clone URL: git://gist.github.com/214696.git
Embed All Files: show embed
Ruby #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
      def setup_io_restoration
        @finalizers ||= []
        [STDIN, STDOUT, STDERR].each do |io|
          dup = io.dup
          @finalizers.push(
            lambda do
              a = io.respond_to?(:stat) && io.stat
              b = dup.respond_to?(:stat) && dup.stat
              unchanged = (a&&b && a.dev==b.dev && a.ino==b.ino)
              unchanged ? dup.close : io.reopen(dup)
            end
          )
        end
      end