From: Sonny Chee Date: 2007-04-07T02:09:32+09:00 Subject: Re: A convoluted question about stdout Thanks Sean. This is exactly what I was looking for.... for some reason I overlooked the StringIO class when I was perusing the Standard Library listing. Sonny. Sean O'halpin wrote: > On 4/6/07, Sonny Chee wrote: >> >> > Maybe something like this (a variation on Bruce's post): > > def capture_stdout(&block) > raise ArgumentError, "No block given" if !block_given? > old_stdout = $stdout > $stdout = sio = StringIO.new > yield > $stdout = old_stdout > sio.rewind > sio.read > end > > txt = capture_stdout do > puts "dlroW olleH" > end > puts txt.reverse > > Regards, > Sean -- Posted via http://www.ruby-forum.com/.