Sha256: 9d348eaafdb8e21bdfd44b06e5567642bfae83530544e0661bcafd1c95991ecb

Contents?: true

Size: 861 Bytes

Versions: 33

Compression:

Stored size: 861 Bytes

Contents

##
# Allows $stdout to be set via Thread.current[:stdout] per thread.
# By Eric Hodel, taken from http://blog.segment7.net/articles/2006/08/16/setting-stdout-per-thread

# Thread local $stdout.
module ThreadOut #:nodoc:

  ##
  # Writes to Thread.current[:stdout] instead of STDOUT if the thread local is
  # set.

  def self.write(stuff)
    if Thread.current[:stdout] then
      Thread.current[:stdout].write stuff 
    else
      STDOUT.write stuff
    end
  end
  
  def self.<<(stuff)
      self.write(stuff)
  end
  
  def self.output_to(io)
      if block_given?
          prev_out = Thread.current[:stdout]
          Thread.current[:stdout] = io
          yield
          Thread.current[:stdout] = prev_out
      else
          Thread.current[:stdout] = io
      end
  end
  
  def output_to(io, &proc)
      self.class.output_to(io, &proc)
  end
  
end

Version data entries

33 entries across 33 versions & 1 rubygems

Version Path
spiderfw-0.6.23 lib/spiderfw/utils/thread_out.rb
spiderfw-0.6.22 lib/spiderfw/utils/thread_out.rb
spiderfw-0.6.21 lib/spiderfw/utils/thread_out.rb
spiderfw-0.6.20 lib/spiderfw/utils/thread_out.rb
spiderfw-0.6.19 lib/spiderfw/utils/thread_out.rb
spiderfw-0.6.18 lib/spiderfw/utils/thread_out.rb
spiderfw-0.6.17 lib/spiderfw/utils/thread_out.rb
spiderfw-0.6.16 lib/spiderfw/utils/thread_out.rb
spiderfw-0.6.15 lib/spiderfw/utils/thread_out.rb
spiderfw-0.6.14 lib/spiderfw/utils/thread_out.rb
spiderfw-0.6.13 lib/spiderfw/utils/thread_out.rb
spiderfw-0.6.12 lib/spiderfw/utils/thread_out.rb
spiderfw-0.6.11 lib/spiderfw/utils/thread_out.rb
spiderfw-0.6.10 lib/spiderfw/utils/thread_out.rb
spiderfw-0.6.9 lib/spiderfw/utils/thread_out.rb
spiderfw-0.6.8 lib/spiderfw/utils/thread_out.rb
spiderfw-0.6.7 lib/spiderfw/utils/thread_out.rb
spiderfw-0.6.6 lib/spiderfw/utils/thread_out.rb
spiderfw-0.6.5 lib/spiderfw/utils/thread_out.rb
spiderfw-0.6.4 lib/spiderfw/utils/thread_out.rb