From: kwa@... (makotz) Date: 2003-03-26T18:47:06+09:00 Subject: Re: [Q] changing a stream of 'print' method to a string Thank you, Gavin. 'stringio' is very useful. I didn't know it. It seemed to be a feature of Ruby 1.8, so I installed Ruby Shim. http://raa.ruby-lang.org/list.rhtml?name=shim-ruby16_18 regards, makotz Gavin Sinclair wrote: > > def print_list(list, out=STDOUT) > list.each_with_index do |item, index| > out.print "#{index+1}: #{item}\n" > end > end > > In your test case: > > require 'stringio' > > buf = "" > StringIO.open(buf, 'w') do |io| > print_list(list, io) > end > > assert_equal(expected_result, buf) > > > I think I got that right. > > Gavin