Sha256: f3d786cd9d17e0f970702ff5953fe0af7cc45e02a5dc04b2efb444aec9575416

Contents?: true

Size: 324 Bytes

Versions: 10

Compression:

Stored size: 324 Bytes

Contents

require 'stringio'
 
module Kernel
 
  # Captures STDOUT content and returns it as a string
  #
  #   >> capture_stdout do
  #   >>   puts 'Heya'
  #   >> end
  #   => "Heya\n"
  def capture_stdout # :yields:
    out = StringIO.new
    $stdout = out
    yield
    return out.string
  ensure
    $stdout = STDOUT
  end
 
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
iron-extensions-1.2.2 lib/iron/extensions/kernel.rb
iron-extensions-1.2.1 lib/iron/extensions/kernel.rb
iron-extensions-1.2.0 lib/iron/extensions/kernel.rb
iron-extensions-1.1.5 lib/iron/extensions/kernel.rb
iron-extensions-1.1.4 lib/iron/extensions/kernel.rb
iron-extensions-1.1.3 lib/iron/extensions/kernel.rb
iron-extensions-1.1.2 lib/iron/extensions/kernel.rb
iron-extensions-1.1.1 lib/iron/extensions/kernel.rb
iron-extensions-1.1.0 lib/iron/extensions/kernel.rb
iron-extensions-1.0.1 lib/iron/extensions/kernel.rb