Sha256: 3c3d918814b8f6a012ea10838209708ef160a911c07390a39f31cfb0a63a2f33
Contents?: true
Size: 701 Bytes
Versions: 3
Compression:
Stored size: 701 Bytes
Contents
require 'stringio' module NoStdout module InstanceMethods def no_stdout ( to = StringIO.new('','r+'), &block ) # supply an IO of your own to capture STDOUT, otherwise it's put in a StringIO orig_stdout = $stdout $stdout = @alt_stdout = to result = yield $stdout = orig_stdout result end def last_stdout return nil unless @alt_stdout @alt_stdout.rewind @alt_stdout.read end end # TODO - explain / remember why this has two class_eval blocks - # should one be an extend? def self.included klass klass.class_eval do include InstanceMethods end klass.extend InstanceMethods end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
davidlee-state-fu-0.0.1 | lib/no_stdout.rb |
davidlee-state-fu-0.0.2 | lib/no_stdout.rb |
davidlee-state-fu-0.2.0 | lib/no_stdout.rb |