Sha256: 89568ee2d3a2b3fab4a4cc61d26d0f2b1990705b7f9cc56a10741dd7f299dff3

Contents?: true

Size: 751 Bytes

Versions: 7

Compression:

Stored size: 751 Bytes

Contents

#!/usr/local/bin/ruby -w

# Run as: echo Bart Lisa | ./withio_test.rb && echo == && cat /tmp/xcv
# Expecting the output:
#	first line is 'Bart Lisa'
#	saved line 'Eric'
#	died in withIO: divided by 0
#	saved line was 'Eric'
#	==
#	first line was 'Bart Lisa'
#	oldout is of class IO

require 'stringio'
require 'scottkit/withio'

saved = nil
begin
  line = gets
  puts "first line is '#{line.chomp}'"
  withIO(StringIO.new("Eric\nthe"), File.new("/tmp/xcv", "w")) do
    |oldin, oldout|
    puts "first line was '#{line.chomp}'"
    puts "oldout is of class #{oldout.class}"
    saved = gets
    oldout.puts "saved line '#{saved.chomp}'"
    puts 1/0
  end
rescue Exception => e
  puts "died in withIO: #{e}"
end
puts "saved line was '#{saved.chomp}'"

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
scottkit-1.6.0 test/withio_test.rb
scottkit-1.5.0 test/withio_test.rb
scottkit-1.4.0 test/withio_test.rb
scottkit-1.3.0 test/withio_test.rb
scottkit-1.2.0 test/withio_test.rb
scottkit-1.1.0 test/withio_test.rb
scottkit-1.0.0 test/withio_test.rb